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_enqueue_scripts not working in custom theme
- How Do I Use The WordPress Plugin Posts 2 Posts by Scribu?
- Need to create a Theme demo site that features multiple themes
- Why does including a file in theme’s functions.php not work?
- login to wordpress with Get variables instead of Post
- Should I use RIPS tool to test my themes and plugins?
- Add Top-Level Menu that opens URL
- plugin for wp_list_categories with posts
- Display All Non-Used Plugins
- Adding “ ” before the last word in multiple defined areas with a plugin
- How to limit 1 image per post on homepage only?
- Flickr plugin that will display photos from multiple group pools? [closed]
- Regenerate images with automatic ALT and TITLE attributes
- PHP Fatal error: Call to undefined function plugin_basename
- Cron job not firing
- WP Query. Is there a maximum size?
- Great blogs site resources/tutorial for WordPress Developers? [closed]
- Recent posts per category loop?
- How to limit image size for the entire website ? But without editing the post (css/plugin?!)
- Set Multiple Meta Values as an Array Using dispatch( ‘core/editor’ ).editPost() Call in Gutenberg/JS
- download button for audio file in post [closed]
- Print posts category or tag as a formatted journal
- How to translate wordpress error message
- Post deleted in trash [closed]
- WordPress API functions not working at AJAX functions.php call
- How to relate 3 wordpress components with each other (Create database relationships)
- how to design change in woocommerce cart page and all other page also by theme? [closed]
- problem with register_activation_hook in plugin
- Override methods in Yoast SEO breadcrumb class
- More gentle way to hook WordPress custom url
- Build a must-use plugin that tracks when other plugins are activated or deactivated
- What snippet do I need to type to show my ACF field show up on my theme?
- Xamp installed local wordpress not allowing to publish or install plugin
- page duplication on wordpress that wont stop
- the_posts_pagination() not working if I add wp_head() to header.php
- FPDF for creating pdf diplomas
- adding dynamic/multiple slug values in ‘option_none_value’
- Conditional required fields for WordPress Contact Form 7
- WordPress plugin options need to delete after deactivate & uninstall
- WordPress function to add text
- Directory structure for plugin changes
- How to work email subscribe in WordPress?
- Is there a WordPress Plugin like Imsanity that keeps high resolution originals? [closed]
- Editing a theme
- How to disable plugin capability : “create new category”
- WordPress Custom Page Blog Template Pagination Problem (Pagination Not Displaying)
- How to make content as required in custom post type?
- What are Seeds? [closed]
- Shortcode cannot parse attributes within double quotes. ” is becoming ” breaking my shortcode