To add your custom class to the old posts at once, you can do this via “the_content” filter and using preg_replace or preg_replace_callback function to do a REGEX replacement.
A working Example:
add_filter( 'the_content', function( $content ){
// Don't do anything if we're not in a single post
if(! is_singular()){
return $content;
}
$customClass="custom-class";
return preg_replace_callback(
'/<pre([^>]+)class="([^"]+)"/i',
function( $matches )use( $customClass ){
return '<pre' . $matches[1] . 'class="' . trim($matches[2]) . ' ' . $customClass . '"';
},
$content
);
} );
Related Posts:
- How to publish a post with empty title and empty content?
- delete post also attachments
- How to get new post URL?
- Allow role to delete posts but block him the wp-admin
- Why does `url_to_postid` return 0 when testing `page_for_posts` Page?
- how “manage_posts_custom_column” action hook relate to “manage_${post_type}_columns” filter hook?
- Delete Post From Front-End and attachment permanently
- Filter Posts By Tag
- Run a function when post is deleted?
- Animated gif for a thumbs
- Posts vs. Pages
- Filter Custom Post Type by Category with Ajax
- Ajax posts filter by date, comments, top views, top likes
- Change post order random through out the entire WordPress
- How to allow visitors to filter posts by multiple taxonomies
- Redirect to another page using contact form 7? [closed]
- disable Tab post on nav-menus page (Admin)
- Adding bootstrap classes to video shortcodes
- Format latest/newest post differently
- Getting Whitescreen when publishing a post [closed]
- Optimize CPT-function with a loop
- Trying to exclude custom posts based on date, while sorting by custom field
- Help on conditional statement to accompany wp_insert_post function please?
- How to put the author of the post in the comments?
- Alt text attributes not showing over portfolio images
- Include Recent Post in Category
- How to delete/customize imported demo content from a theme or add my own?
- Hiding title of selected post without plugins
- How to modify specific parts of a post content in WordPress
- Automatically delete default posts and pages on theme install?
- Filters do not work when there are multiple (one works)
- Edit Page button is gone
- How to set something to added automatically to the post
- Add function to single blog post pages only
- Modify WP_Post before processing
- How to rename “Publish” metabox title in post screen
- str_replace function in theme
- Archive Page for Custom Post Type is not Working
- How to filter posts that belong to a specific category only if that is the only category
- Sidebar links for different pages
- Dynamic carousel on individual posts
- Action hook for new pending posts?
- How to retrieve the postID in a “image_send_to_editor” hook function?
- Uppercase first sentence in every post
- Add icon/badge next to posttitle of specific category
- Edit custom post type admin menu link
- Deleted category by mistake, all posts now have categorized category. Can i revert that?
- How to add Tags Filter in wordpress admin dashboard
- Prepend or add an Image to the content of a Post
- Converting a dynamic piece of code using WordPress Loop into a static one using Post ID
- Replace ‘published on date’ with ‘modified on date’ on Posts
- Why content_arr[‘extended’] removes paragraph tags?
- pre_get_posts query between 2 dates (date stored in custom post meta)
- Applying $posts_clauses filter to specific queries only
- Why orderby=”date” does not support manually changed posts?
- how to remove dash (-) post status from post title on posts listing page wordpress
- What is the standard featured image size?
- Blog Posts in Custom Menu
- Admin Posts Table Column Fitlering is not working for Custom Post Type
- Get latest posts from WordPress site without header, menu and sidebar
- Modify Image Source With The_Content Filter?
- I am unable to publish/update post
- is_customize_preview() like function to check if Customizer “Live Preview” in JavaScript
- How to display data in archive page?
- Delete post by giving its link
- How to add pagination in between post and comments?
- How to include a post type in the admin/backend?
- Set terms in a custom post
- Get posts of ONE taxonomy term of custom post type
- WordPress Custom Fields (Checkboxes with multiple values)
- Load post attached images on a single page site with fancybox
- How to show single post page as home page
- I want to display custom text widgets for each post in the sidebar?
- How to make number of blog posts a custom field?
- Display posts styled exactly like default posts
- WordPress blog or WordPress website
- How to make classes for posts?
- Why aren’t my posts/pages showing up in my WordPress Theme?
- Using custom post template
- Custom Post Archive Page not working
- Hiding Draft Post In Admin
- Exclude category from
- Print all the tags from a custom post type Please
- Blog page not working
- What is the filter or hook to add admin controls to posts on the front end?
- Display multiple custom taxonomy values on single custom post types page?
- Setting posts_per_page for taxonomy term template
- Adding custom fields to bbpress reply form
- Move first half of posts to one parent page, second half to the other page
- Adding buttons to Add New Post and Add New Page
- use wpml_post_language_details function other plugin based on $post->ID [closed]
- Custom Post Type – Category Rewrite – Remove Rewrite from Sitemap
- How to hide html tags on revision comparison pages?
- Add filter by custom field to block of posts
- CPT archive redirects to single post
- How to display the link (title) and thumbnail post?
- Ajax post filters not working
- Default to ‘all’ view on the ‘edit-post’ screen for authors
- Show posts by a custom post author
- Force the “Choose from the most used tags” meta box section to always be expanded