I would say you can’t, not possible. There is no filter for get_the_post_thumbnail_url()
or get_post_thumbnail_id()
.
However you could apply a filter to get_metadata()
which get_post_thumbnail_id()
uses, and return the id of another attachment that you want to use as the default thumbnail. But I don’t recommend this it’s a bit hacky.
I think you should refactor your code and just make a function to check if get_post_thumbnail_id returns anything.
Related Posts:
- Add ‘if exists’ to filter
- How to removes all instances of thumbnails displayed in my theme?
- Override has_post_thumbnail function
- Removing URL and adding container around image in the featured image metabox
- How to apply filter on get_the_post_thumbnail()
- Distinguish between page and post in function
- WordPress set featured image to first image of the post
- Set post featured image to author image
- How to filter wp_get_recent_posts() to only posts that have thumbnails?
- changing size image within the content
- can’t output gray scaled image I’ve created using add_image_size
- Wrapping Featured Image on Add/Edit Page in div?
- add_filter with specific thumb names
- Changing WooCommerce Display Price Based on User Role & Category [closed]
- Not able to change wp_title using add_filter
- Advanced Custom Fields and Yoast SEO keyword analysis [closed]
- Insert Custom HTML After Shortcode
- What do add_filters() and apply_filter() do?
- SSL certificate for the host could not be verified
- Store source permalink on XMLRPC calls
- What to use instead of the content_save_pre filter?
- How can I customize the wp_list_categories
- How can I reliably and globally disable wptexturize?
- Customise Jetpack Publicize text
- Can’t change a label in woocommerce with the normal filter
- WordPress RSS feed – filter RSS content by custom field value
- What is the filter hook for custom fields content?
- Add classname to the_category() function?
- Filter the URL of next_posts_link & previous_posts_link
- Sensei LMS Hooks to Remove Content
- How to re-enable a filter after disabling with __return_false
- Exclude One Category and its Subcategories using WP_LIST_FILTER
- Explanation for remove_filter used in the below code [closed]
- How to change the blog title with add_filter? details below
- Gutenberg disable the “block” tab in right sidebar
- add_filter to ‘woocommerce_before_main_content’ [closed]
- Editing
- the_content filter – checking the post
- add_filter to apply_filters that exists within class
- Echoing Categories only if they’re a child of a given category
- Adding a title prefix with the the_title filter
- Contact Form 7 filter similar to preprocess_comment [closed]
- How to modify an existing meta description?
- Adding TinyMCE buttons without removing plugin buttons?
- How can I include an existing custom sitemaps listing in wp-sitemap.xml?
- Display Externally Retrieved Data within a Custom Template
- Can the wordpress color palettes by changed through Javascript?
- Filter on the_content doesn’t update the content being searched via register_rest_route
- Where to add_filter in theme functions.php?
- tag removed not using a filter
- How to customize the “Insert/edit link” popup box?
- How to filter backend post list showing only posts having a shortcode
- WordPress Image update filter
- How to remove this filter?
- Why does WordPress strip custom HTML that are form elements and theme SVG icons?
- Get current user data
- How can you wrap add_filter with a if is_home() statement?
- How to add attributes to WordPress Admin Sub Menu List Items
- How to disable thumbnail filter for a specific template part or image size?
- How to combine multiple body classes
- How to replace username with email address in users table
- How to write a filter to remove a form field (WordPress) [closed]
- why require – does not load filter
- term_link filter rewrite link only applying half of condition?
- How to change dynamically page title according to variable data?
- Map plugin with proximity search compatible with Buddypress
- Create a pre-filtered version of the Media Library
- What is the action hook to use if you want to capture the new password during password change?
- Get_template_part inside filter?
- How to filter Sidebar Content
- How would I use a filter to remove header banner on certain post types
- Need to return shortcode text instead of the output
- Dashboard filter based on custom fields URL response code
- Customising the default wordpress search functionality
- I want to add string array to this function to filter displayed option in drpodown [closed]
- Ajax filter – show all results that contain at least one filter
- How to add a blog filter bar without paying money. (example inside)
- How to wrap pattern-matches from the_content in [wiki]-shortcode tags
- Print only parent categories of post in custom RSS feed
- WordPress: Issue with filtering users using date range
- Use add_filter inside another function
- Remove the post_content search from WHERE clause (and CONCAT sql function)
- mu-plugins body_class filter not working
- How to apply a filter to everything?
- WP Job Manager – display search results from custom search form in taxonomy-job_listing_category page
- Conditionally (cpt) filter previous and next_post_link
- Post filter Month dropdown at front-end like wordpress backend
- WP Dashboard -> Posts-> Filter by Category -> Form Method Change : Which Hook
- Show child theme for users on specific IP
- Is there a way to overwrite a filter used in canonical.php?
- How do I remove certain HTML elements with specific classes from the feed?
- Sanitizing a custom query’s clauses
- How can I display wp_link_pages before a shortcode, if it is used, or display after content?
- confusion with add_filter
- post->post_content filter
- How to change this WP logo and posts url in block editor?
- Better way to change the default password reset url with the woocommerce one?
- woocommerce_coupon_is_valid_for_product not working to exclude specific product tag
- Replacing text using add_filter
- Background color and background image below element in Contact Form 7 – error tip [closed]