Snippet: Set A Background Image For The Page Title On All Pages/Posts
This snippet shows you how you can define a custom background image to be used on all blog posts. Simply alter the conditionals accordingly to affect various parts of your site that you want to modify.
// Change the page header style
add_filter( 'totaltheme/page/header/style', function( $style ) {
// Change the page header style to "background-image" for all blog posts
if ( is_singular( 'post' ) ) {
$style = 'background-image';
}
// Return style
return $style;
} );
// Change the page header background image
add_filter( 'wpex_page_header_background_image', function( $image ) {
// Set a custom page header background image for all blog posts
if ( is_singular( 'post' ) ) {
// Define your image url or ID => An attachment ID is always best
$image = 'YOUR_IMAGE_URL_OR_ATTACHMENT_ID';
// You can use get_post_thumbnail_id() to use the post thumbnail) if you prefer like this
if ( $thumbnail = get_post_thumbnail_id() ) {
$image = $thumbnail;
}
}
// Return image
return $image;
} );
All PHP snippets should be added via child theme's functions.php file or via a plugin (we recommend WPCode)