Get the Featured Image of a parent page in WordPress

Another WordPress Snippet

When you’re building a number of pages in WordPress that are closely tied to a main, or parent page, tying them together with imagery can help the user know where they are.

This snippet is from the same book project as this snippet that gets the title of the parent page. It allows us to show the same header image on all subsequent chapters of a book (child pages)>

The snippet

srcset for the responsive

The beauty of this snippet is that it uses WordPress’ built in responsive image support, introduced in WordPress 4.4. This allows a browser to use the best sized image available using the srcset attribute, potentially saving bandwidth and speeding up page load times in the process.

Put it in a template file

This code is meant to be placed anywhere in a template file that you’d need to display the Featured Image of a parent page.

Leave a Reply

Your email address will not be published. Required fields are marked *

Tell us about your project.

We'd love to hear what you're working on.

Work with us

Hi. We are Spigot. Telemarketers pronounce it Spy-got.

We are a Park City, Utah based web design shop that excels at building custom websites powered by WordPress and WooCommerce. We love content - content strategy, content curation, content soup...????Have a look around the site. As you browse you'll find useful navigation links in the sidebar on the left. We hope you find them useful anyway... Please let us know what you think, shoot us a message here.