You have the global WP_Post object available so you can look the post type like this:
function wrap_post_images_to_div( $content ) {
if ( get_post()->post_type === 'post' ) {
$pattern = '/(<img([^>]*)>)/i';
$replacement="<div class="well text-center">$1</div>";
$content = preg_replace( $pattern, $replacement, $content );
}
return $content;
}
add_filter( 'the_content', 'wrap_post_images_to_div' );
You can use the preg_replace_callback instead to filter the matches with certain ids from the matches.
Related Posts:
- Redirect to another page using contact form 7? [closed]
- Can we completely remove the WordPress Sitemaps (WordPress 5.5)?
- Display post lists in 2nd paragraph
- Between functions.php (theme), widgets, and plugins, which is loaded first?
- Manually set global $post vars with an ID, in order to use template tags
- Limit access to posts/pages by user roles
- Adding a text domain to every __(), _e() and __n() gettext call without a plan to create own translations
- Seeking clarification on page request life-cycle
- How to extract images of post and pages excluding header and logo image in wordpress?
- Code in theme functions.php faster than with a plugin?
- Disabling post images for not logged in users
- resize only height using wp_get_image_editor
- Converting a simple plugin to be placed inside of functions.php
- Showing Co-Authors on post page
- How to change ID of an attachment in wp_posts and its related tables correctly?
- bulk change of image setting “link to” to “link to: image url “
- Bulk Image Uploader to create new post from each image [closed]
- Get the url of the full sized attachment image using post ID?
- Override the filter from plugin in child theme
- Adding Attachment Display Settings in custom media frame
- Custom Taxonomy Tag Search
- Inserting HTML tag with ACF into shortcode
- How to Display a Plugin function (content) on frontpage using index.php
- The problem with WordPress Importer
- Image change on hover
- How to write “alt” tag in image for wordpress code?
- How can I automatically download all images from all imported posts, place them on my new host, and replace all the links
- Shortcode Attributes to Return different $_POST
- Woocommerce singe product custom gallery output works just on the first slide
- Where Should i write the code for wordpress ajax voting?
- Set up functions to be overridden without using function_exists() by short-circuiting them?
- how can authors to define custom pages?
- Add_image_size not generating correct size
- Is there a way to insert multiple images into a post at the same time without using a gallery?
- Removing the custom_image_header from wp_head
- Elementor Pro display featured image on section -> style -> image using shortcode
- How would I get the new plugin version on this function?
- Copy/paste local images not working in WordPress
- Unpublished Pages Failing To Appear On Custom Path
- Submitting form to PHP
- Conditional Homepage for logged in user
- How can I see $post object in frontend from functions.php?
- Is it possible to customize a wordpress post from outside dashboard(Something like site.com/post-type/post/?e=post_id)?
- How can I add a custom checkbox / radio button on the admin theme options to display a CSS or other?
- Is there any hook to change media html in post? [duplicate]
- How to force regenerate thumbnails in WordPress posts?
- How to show post attachment image
- Can anyone tell me why I can’t edit a plugin when it is installed without having to re-install?
- Retrieve post thumbnails
- Notifications Bar on home page only
- Show WooCommerce products based on query parameters on redirect
- WP galleries in posts after import. How do I do it?
- Difference and examples of esc_attr__() and esc_attr_e()
- Jquery NoConflict Problem
- AJAX fileupload – TypeError: not a function ajaxSubmit()
- Problem of encoding characters (apostrophes) in my posts publications
- How to backup single post in wordpress [closed]
- Proper way to use plugin functions in functions.php
- How to change the post form from plugin?
- Allowing users to Sign-up > Login > Post articles that need approval
- How can I support plugins in a custom theme?
- Remove Pagination for Product Category Pages WooCommerce
- Is there a plugin or a way in the wordpress that would let us have different versions of a post or page accessibe to users?
- All custom widgets are not showing in widget area at the same time
- How can I use my custom wordpress theme on two websites? [closed]
- Search by Attachment ID
- Send post changes to set email addresses (not users or subscribers)
- Hardcode a form in Contact Form 7 [closed]
- How to make excerpt image be full size instead of thumbnail?
- auto activate plugin when theme is active
- Checkbox show / hide output result
- How to keep plugin (media-sync) running even the tab is closed?
- Load CSS before Theme CSS
- Custom Logo Link WordPress
- Where do I put the code snippets I found here or somewhere else on the web?
- Is it possible to pin a post in second position from top
- How to convert Currency from USD to other IP Based currency in Php function
- Attempting to list all product categories and the price range of all products within them
- Is classical wordpress eidtor a good option for me to include a large table with a large number of images on my webpage?
- Newbie problem with adding include wp_footer
- Creating an array from form inputs before it is posted to the options database
- Optimise wordpress database using SQL after deleting registered images from Media Folder
- function post to trash problem
- How to assign a specific service to a specific provider based on location
- Allow members to create groups on my site
- when i activate my WordPress plugin cannot see customizer options or preview
- Get plugin to background of page
- Add dynamic color to each category item
- Code fails in plugin file but works in functions.php
- WordPress get_post_meta issue
- Cannot access variables within a widget
- adding image in the header of my dev widget
- get post excerpt by query
- Advanced Custom Fields (ACF) Plugin – Random Image in Sidebar
- Doing action based on input from options menu
- Images not showing and plugins not installing on wordpress server move
- How to generate a responsive output from plugin?
- Sync roles across several plugins
- Images get uploaded itself from the computer
- Shortcode returning specific content of a post