You did not mention or shown in the code to which hook are you hooking the above code to, but here’s what I think should work. NOT TESTED
global $post;
$header_image="";
// featured image is first priority, right?
if ( has_post_thumbnail( $post->ID ) ) {
$header_image = get_the_post_thumbnail_url( $post->ID, 'full' );
} elseif ( !empty( get_header_image() ) ) {
$header_image = get_header_image();
}
$header_image_css = ".blog__header { background-image: url({$header_image}); }";
wp_add_inline_style( 'theme-styles', $header_image_css );
Related Posts:
- The the_post_thumbnail without srcset?
- Cannot get full thumbnail size using the_post_thumbnail
- How to add cropped custom header image?
- How do I remove header/page-title image in farvis theme? [closed]
- Featured Image Module Randomly Disappears
- Show post thumbnail only if it exists using timthumb
- Get the first image from post content (eg.: hotlinked images)
- WP 3.4 – what action/hook is called when theme customisation is saved?
- Add a dropdown to theme customizer
- Is it good to rename theme folder downloaded from WordPress.org?
- What is the problem if I use CDN in my WordPress parent theme(built using bootstrap)?
- Is it possible to use line break in theme description?
- Is the theme customizer slowing down my site?
- How can I get wp_head() as a string instead of echoing it?
- Grab the first paragraph of each post
- How to change post thumbnail title and alt attributes to post title?
- How to check if post has any tag?
- How do I “unhook” / de-register jQuery so that it’s not called as part of wp_footer();?
- Example of a theme organization without all the default wp files in root
- Which is the simplest theme for WordPress to use it as your base?
- “Cheatin’ uh?” error message on multple theme directories
- Adding WordPress colorpicker in widget settings
- Disable the Custom Internal CSS added by theme.json for Certain Pages
- Unwanted blank lines before tag
- A theme that follows all the best practices to learn from?
- get_post() function returns post even if it is trashed
- How to highlight the current page in the nav menu?
- “Display Site Title and Tagline” checkbox not working?
- Add social icons in a theme through custom admin menu
- file_get_contents Not allowed in Themes?
- How to regenerate thumbnails when they’re stored on S3
- Custom Nav Walker Displaying Values in Sub Menu
- How do I remove twentyten without ruining what I did?
- Custom theme not visible in Appearance
- Can’t delete theme
- How to add a second stylesheet to the editor
- Can’t show custom post thumbnail sizes as background images
- Developing WordPress Theme using CSS framework like Bootstrap
- WP_Customize_Color_Control omitting # symbol
- Single Page theme [closed]
- Theme translation not applying
- How to add filter the post thumbnail before save in database?
- Can I have two different theme for two different language?
- How do I Add images uploaded in the post to a default custom field
- Storefront child theme not applying parent theme [closed]
- WP_Comment_Query – Get comments and answers separately
- excerpt() shows different result between remote and localhost(development environment)
- Theme Javascript.php Overwritten Nightly [closed]
- Theme Inspector “X-Ray”
- Acivate all themes multisite wide automatically
- How to place HTML tags in content from the_content()?
- WordPress Theme Creation [closed]
- What is the meaning of WordPress’s recommended css classes and where are they applied?
- Integrate WooCommerce theme with a WordPress theme [closed]
- Automated Footer information
- How do you use WordPress for a website that’s not in a blog format?
- Dynamic Post Thumbnail →
- Simple child theme modification but links are broken
- Making a WordPress theme based on twentyten
- How can I wrap all blog posts image with
- theme style is applied on the dhasboard rather than the website
- Alignment Problem [closed]
- What $handle does WordPress use for a theme’s implicit style.css?
- Issue when posting updates/changes to wordress
- Create theme for mobile phones and tablets only?
- Unwanted empty line at the beginning of document
- Why is my container argument not working for wp_nav_menu() [closed]
- Never actually adding the action? Or do I have to call the action?
- best practices for updating wordpress theme
- How can I get the featured image or the first image for a post/page and display it as a banner?
- help needed for suit designing tool
- Add image URL automatically to custom field?
- How to modify theme content in Thematic?
- How to update mark-up of a gallery block in a custom theme?
- Host Private Custom Theme
- My wordpress theme name isn’t updating straight away
- Why front-page.php doesn’t show content of file instead shows loop
- Customizer API Multi Sections in single Panel
- WordPress theme options checkbox default checked state
- Copying a modified theme from one wordpress site to another wordpress site [closed]
- How can I change this SVG shape that’s generated?
- Adding a second logo next to the main one in header
- (Parent) theme Is Not Showing In Theme Selection Panel and Therefore Breaks Child Theme
- How can I fix my theme header for my CSS stylesheet?
- How to show some of category in wordpress
- using themename_the_custom_logo() in template-tags?
- Creating a theme just to deploy a single page
- Custom page template not showing on page creation
- Custom theme vs theme customization?
- Weird ‘theme update’ error [duplicate]
- Single Featured Image Repeating
- “No Data Received” error in Chrome every time i try to update the theme functions file
- WordPress two sidebar layout or theme
- apply_filters to featured image
- Standard Way To Do Custom Work Within A Page?
- Confused on loading page content
- Add Dynamic Sidebar to Exisiting WordPress Theme [closed]
- How can I install my custom-made theme on a wordpress.com blog? [closed]
- .submenu class missing in output from wp_nav_menu
- How do I send out an update for my custom wordpress theme?