By using post id you can get post type of current post/page. try below code. i have tested and it is working fine for me.
add_filter( 'admin_post_thumbnail_html', 'foo',10,3 );
function foo( $content, $post_id, $thumbnail_id ) {
if ( get_post_type( $post_id ) == 'page' ) {
$content="<p>foobar</p>" . $content;
}
else{
$content="<p>barfoo</p>" . $content;
}
return $content;
}
Let me know if this works for you!
Related Posts:
- Add ‘if exists’ to filter
- How can I filter block registration based on post-type? (Block alignment settings)
- 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
- Filter Media by attached page or blog post in Library
- How to apply filter on get_the_post_thumbnail()
- WordPress set featured image to first image of the post
- Set post featured image to author image
- Print url to default featured 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
- Add custom options to the wplink dialog
- Sanitize and data validation with apply_filters() function
- How many filter/action hooks are healthy?
- Filter specific shortcode output?
- Insert new element to array with add_filter
- How to hook into unregistering a widget instance?
- How can I extend the Gutenberg table block transform to allow colspans/rowspans on pasted table elements?
- How do I use the ‘http_request_host_is_external’ filter
- get_option() filtering and getting out of recursion
- Get excerpt from $post->post_content
- How can I add information underneath the user’s name on the users.php page?
- Is calling function_exists() faster or slower that apply_filters()
- Filtered query_vars becomes global. Why does this work?
- How can I filter Microsoft Word gunk from pasted content?
- How to disable all WordPress emails modularly and programatically?
- Allow Profile HTML for select users
- Alter only the page title, not the post titles within
- WordPress 3.5+ upload tool filter
- Search with filters and title
- Use content custom filter for all shortcodes
- Filter all html output
- How to specify which category of the post to use in case of multiple categories
- Return array of images after content
- failed to filter hook `get_terms_defaults`
- Filter list by a unique meta value dilemma
- How to use shortcode attribute in separate function
- Is it possible to track down Actions and Filters?
- How can filters be run when they are never applied?
- How to filter a wordpress core function?
- Adding id and class to the search input in WordPress search form
- get_bookmarks filter not supplying query argument (wp 3.1)
- Filter Posts by current Month
- Is there a filter called ‘network_admin_init’?
- Post Content, Special Characters and Filters
- Correct method of redirecting user login
- How to filter for user registration, be able to throw error message
- Admin filter for product SKU?
- Contact Form 7: Make field required after checkbox is checked
- Customize title, description and focused keyword [closed]
- Filtering the post list in the admin area
- Filter pre_get_posts does not modify Mine/All/Pending
- wp_mail works with add_action(‘save_post’, …) but not an ajax action
- How to check if a protected hook is hooked?
- Can i use multiple ‘the_content’ filters?
- Is it possible to put the add-filter()-hook into a function?
- How can I return shortcode output to the top of the content?
- Filter for when the post is updated
- term_link filter gives less atributes
- Filter a pluggable function
- Add mime types with plugin
- Filter media upload attachment meta
- Filter have_posts()/ the_post()
- Filter wp_redirect() to stop redirect under certain condition
- How to add filter in custom rss feed
- Echo string in admin panel footer beside version no
- How to change default text for specific post type
- Add PHP code after title in single post pages?
- How to stop the deduction in “wp_term_taxonomy” count, when the post is deleted?
- How To Get Search Term and Use in Function
- Add filter on certain thumbnail sizes only
- How to pass a variable between filter/action functions?
- Filter the title to only affect the_title() template function
- how to unescape wordpress output
- How can I limit access to uploaded media depending on the logged in user’s user role?
- Database & Post Search
- login_url filter creates permanent wp-admin -> wp-login redirection loop
- Modify Contextual Help
- Widget image reorganize layout
- Modify WordPress search behaviour in backend?
- Modify category listing API response
- Auto-generated excerpt with shortcode and read more button/text link
- Testing requested query in pre_get_posts
- Converting restricted html in comments to bbcode
- What is the proper/best way to have multiple add_filter for wp-job-manager-resume
- Modify WooCommerce email shipping text value
- How to replace all images in all posts and pages with a different size?
- Using Filters To Change Page Title
- How to add a class to Buddypress avatars in the Activity stream? [closed]
- using posts_where for meta data on pre_get_posts
- apply_filters to featured image
- How properly write function to filter content in a template for plugin “multiple content blocks”
- ACF Load Field Groups Programmatically [closed]
- Query Multiple Filters, one with Meta
- How to remove a filter that is an object method?
- Search and Filter Using Custom Post Type, Custom Taxonomy, and Advanced Custom Fields