The post_thumbnail_html
action hook will be the one you’re looking for. This allows you to add conditional logic to change the source url depending on the page you’re looking at.
function new_post_thumbnail_html( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
$new_html = $html;
if ( is_archive() ) :
$new_html="<img src="https://your-image-source.com" alt="Your image alt tag">";
endif;
return $new_html;
}
add_action( 'post_thumbnail_html', 'new_post_thumbnail_html', 10, 5 );
Depending on how Elementor treats the featured image for your hero section, it may do a has_post_thumbnail()
check before displaying the featured image. In that case, this solution will not work, and you might try this solution instead.
Related Posts:
- Custom plugin: Trying to show saved data on frontend
- How to call a function only once (global variable scope)
- Is there a browser plugin or method to find which php template an item is coming from?
- Where should I install a PHP library into WordPress so that code in a webpage can activate it?
- Does the debug.log do log rotation?
- ob_get_clean returns empty string, ob_get_flush outputs string
- Edit postmeta when user changes user role?
- Pagenavi pagination via wp-query in functions.php showing same content for each page
- WPDB: how to get the value of a field in a custom database table
- Looping through WP_Post Object
- Translating add to cart woocommerce button [closed]
- nowplaying.include.php Will Not Display Results
- Memory errors with media upload, WordPress can’t use more than 96M (while there’s 512 available!)
- SetCookie simply not working
- Looking for most performant way to execute several similar WP queries within shortcodes
- Show MySQL errors that occur when I excute $wpdb->insert()
- Customize Time Stamp
- Combine two filters into a single call
- The text box have space character
- How to output widget
- 3 blogs same installation, without WP MU
- get_avatar won’t show uploaded avatar, only default gravatar
- How can I fix WordPress installation errors?
- Two Different Links for Same Product – WooCommerce [closed]
- WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
- Display menu point only if there are published posts in that category
- What query string parameter is available for index.php, that works for both pages and blog articles?
- Sending data from custom inputs in WordPress comment form in the admin notification email
- export a csv file from the database with a cronjob
- How to set a min number of words for a blog post
- How to show all pages in blog navigation?
- Setting value of session with Ajax not working
- Click a radio button must set textfield value
- Access Child Class of Plugin Main Class Instance
- Modify custom field input data before creating a new post
- Large Woocommerce Site (83,000 items), What Can I Do? [closed]
- How do I find PHP file that contains content of my page?
- Multiple do_shortcode in page template
- Ajax contact form return 0
- Get my site session in wordpress?
- is_user_logged_in() not working in AJAX validation call
- Change order of custom submenu link in WP Admin?
- Register a menu – Error Header
- How to create a field in customize and show that in header.php?
- I am receiving a pluggable.php warning sign on my only http:// page
- WordPress child pages not working
- Custom map_meta_cap filter does not return [‘do_not_allow’]
- Include style.css in the Child Theme with PHP
- Get user custom field value on function.php
- Add New Text Box To WordPress Twenty Seventeen Header
- WordPress homepage setup not working on first load
- Get the id of all images in a post
- PHP Output also in Child theme, but different
- Choose either excerpt or the_content
- Removed jQuery script from header.php , any problems?
- Dynamically display font icons in widget
- Setting a default thumbnail url if no thumbnail
- How To Pass Array To get_the_category_by_ID() and Get An Array Back?
- conditional: if is page, and all subpages
- Need help for some PHP code
- Remove an action created by a Gravity Forms add-on
- Define global custom post
- How to secure my php forms
- Ajax search box displays nothing if taxonomy doesn’t exist
- PHP “warning include_once(): Failed to open stream” Simple HTML DOM in WordPress Child Theme
- delete functionality wordpress
- Add a custom link to each image in WordPress gallery
- cURL needing to loop through all “next_page”
- How do I make the following articles collapse within the month?
- How can I get my pagination loop to display the correct number of total pages?
- Notice : Array to string conversion on array_intersect user meta
- Get posts by id using shortcode
- Is it possible to replace ‘attachment’ with another word?
- custom field – changing an element or background of id div – different versions not working
- Hide price excluding tax when price is empty
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- Show post/page into div using function
- Getting a value from a custom field from a page that shares a parent with the current page
- wordpress, Category ID
- PHP get_category() function redeclared
- WordPress 404 when using AJAX to call php function
- PHP calling function within a class
- How I can shorten this title length?
- WordPress – registering sidebar and adding a button directly after .textwidget
- Save data of select list after clicking save
- Arrange Category post manually when displayed
- How to change links in the 3 main categories, on widget category, to a javascript function call
- Where can I find the code for the menu page meta boxes?
- WordPress adding in site URL to header links
- Error on Include php:/usr/share/pear
- Php inside the shortcode is getting commented
- Alternative loop syntax error [closed]
- why my “recepie” category is not taken into account in my request
- Category slug inside another php code
- Custom field fetch error on woocommerce pdf invoice
- posts_clauses drop ACF get_field function
- PHP block changed to comment by WordPress?
- WordPress @include( ‘template-config.php’ );
- Is there a hook that I can use when a fatal error occurs?
- How to make posts_like_dislike reference current post when iterating?