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 change the case of all post titles to “Title Case”
- How to display by default only published posts/pages in the admin area?
- Removing any and all inline styles from the_content()
- Post/Page Preview Template
- using wp_update_post on save_post
- WordPress plugin to publish to multiple remote WordPress blogs
- Code to auto expire posts after 30 days
- How to wrap every image in a post with a div?
- Filter posts by author and category simultaneously
- Show One Category on Post
- Custom colors for post rows based on post meta value
- WordPress Delete hook with wp_delete_post function?
- Order post by year DESC and month ASC
- Custom wp_trim_words() function not trimming right
- Do I use custom post type or something else?
- Custom post type permalinks breaking due to 3.1 bug fix
- Function to show random posts from a category
- ‘Invalid post type’ error when importing from one site to another
- Blogroll – Different layout for first post
- How to delete old posts’ edits to save space?
- How to add Tags Filter in wordpress admin dashboard
- is_customize_preview() like function to check if Customizer “Live Preview” in JavaScript
- How to make number of blog posts a custom field?
- WordPress blog or WordPress website
- Hiding Draft Post In Admin
- Ajax post filters not working
- Force the “Choose from the most used tags” meta box section to always be expanded
- Display Meta Values in Custom Filter – Admin Custom Posts
- Making a custom Pagination for multi page blog post
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- How to change the color theme per post?
- Thumbnail & Category link aside post
- WordPress custom post type with folder structure in slug
- Filtering posts on Post Administration Page by Week Number instead of by Month
- Filter nav menu items HTML tags and wrap inner text with span
- Change the default blog post post attribute template name from “default template” to something else
- Is it possible to add a shortcode below post title?
- Defined function isn’t showed on page
- Show custom post with custom categories with specific slug
- Updating permalink structure using ‘post_link’ filter results in 404 error for posts
- Add post tags to previously created custom post type
- wp_list_categories() Exclude All Categories Except One
- How to bulk Update URLs to new values?
- WordPress Sticky Post Count “Fix” Breaking Pagecount by 72 pages!
- Function is printing twice – any suggestions?
- Filtering private Posts
- Remove pagination if search returns empty
- Remove HTML tags from all posts
- Save All Post Permalink From A Specific Category into a .txt file
- How to Display Most View Post in the template file?
- Customizing URL slugs of Custom Post Type and Taxonomy make posts/pages 404
- Show post excerpt
- How do I apply a wordpress function to something with no ID inside an archive page?
- Show author bio box
- Is it possible to completely replace a post with an action/filter?
- How to retrieve custom field values and save again as array
- Call image from post on index page?
- Is there a Standard Format for Clean URLs for Archives of Custom Posts?
- How do I get thumbnails?
- Latest Posts not in the right order
- Notify Author of the post if admin deletes his post and perform some function
- wp_query posts sorting doesn’t work
- How to remove a date from wordpress post
- wordpress pinboard theme [closed]
- Show Next/Previous without Link
- Add multiple HTML attributes to an Elementor button
- Hindi content automatically converting to unreadable language?
- WordPress Custom Post type csv exporter