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?
- How to disable hover zoom on woocommerce. None of the common methods work
- Import posts from a different database with the same old id
- Override the plugin class and function
- Activate and deactivate two plugins automatically at certain hours
- How to escape html code?
- PHP Creating a formula from mysql db values and db stored math operator
- My Blog page ( posts page ) theme isn’t changing with the new theme [closed]
- how to embed a crop feature for cropping images uploaded by the user
- Ajax button “Load more” is not loading correct language version posts for logged out users
- Create WordPress category dynamically
- How to Allow Users to Select Recipients In a WordPress Comment section?
- Can i have limit posts on a specific category and automatically remove older ones?
- manage_{taxonomy}_custom_column not working
- How to Add Extra Text In WordPress Title Before Post Publish
- How often should I execute add_filter and function declaration in Code Snippets?
- How to show image caption in Woocommerce gallery
- WooCommerce: write featured image dimensions to custom fields in product’
- How to code a wordpress page properly? Dashboard or unique Theme files or alternative?
- How to disable plugin capability : “create new category”
- how to make wordpress remember my choice
- Is there a plugin or another way that can help me find out the underlying files of a page/post? [closed]
- Is website for online game guides doable in WordPress? [closed]
- I want to include My theme file (testing.php) to inside my plugin folder (myplugin/mypugin.php)
- filter just a portion of plugin function
- How to Enfroce Domain Licensing Limits? [closed]
- Override plugin constant using a theme
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- Gravity Forms and Gravity View Permissions
- Meta box not displaying on the plugin page
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- add_meta_box showing blank screen in my page
- Option value not getting updated until page refresh in WordPress
- How to create an Info Box on WordPress [closed]
- Make plugin admin page visible to other roles
- How to customized post slider layout in elementor wordpress [closed]
- Product customizing quiz – quiz adding products to the cart
- Achieve the following layout
- WordPress Convert queries to slashes using function.php
- Redirect a specific User role not admins automatically to view the post that they just updated
- How to change all the urls of the WordPress site?
- How to export post tags from wordpress
- Sort posts by Date (DESC) and by ACF: active_inactive (ASC)
- WordPress Custom Page Blog Template Pagination Problem (Pagination Not Displaying)
- wp_enqueue_script doesn’t load JS in plugin
- How to make content as required in custom post type?
- warning wp session
- What are Seeds? [closed]
- Shortcode cannot parse attributes within double quotes. ” is becoming ” breaking my shortcode