Your code is returning $text
only for posts and nothing for other post types like pages.
Your function should be like this
add_filter('the_content', 'replace_word');
function replace_word($text) {
if (is_singular( 'post' )){
$text = str_replace('dog', 'cat', $text);
return $text;
}
// you must return content for pages/ other post types
return $text;
}
Related Posts:
- How to add an admin notice upon post save/update
- Passing current cookies in wp_remote_get to get Draft Post Preview
- Listen to Post action
- Manipulate post category after time
- WooCommerce – Create Products Programatically [closed]
- which action to hook to in order to perform post-publish action
- Cannot access current post’s ID in custom plugin
- Set number of article per number of page
- How to change post status from publish to draft using hook in wordpress?
- prevent showing posts of an specific category in admin posts section
- Using radio button meta data from a custom meta box
- How can I link a CSS file only on single posts?
- Will post_exists work for draft posts?
- How to store an extra (surrogate) ID when creating a post with wp_insert_post?
- Global $post not working in OOP function WordPress
- Category Template: Need to display different content on first page of archives
- Define a wordpress constant through plugin functions?
- How to get post bulk edit action trigger and get edited post ids?
- updating a post doesn’t trigger a function
- Hide a specific category in admin All Posts page (WordPress)
- Prevent Delete Attachment by URL or When Submit
- What hook do you use to update a post?
- Updating post data on save (save_post vs wp_insert_post_data)
- How can I hide tags on a child-category page, if that tag has not been used?
- What happens if I delete all the rows that represents a post revision from the posts table into WordPress database?
- Conditional Tag for has post [closed]
- static landing page leading to author specific pages w/ “live” content
- Filter Hook for post table (not columns)
- Changing Post Tag Color Based On Post Count
- Conditional css for custom post type
- Get author posts count after excluding a category
- Stop post submission without losing data?
- Cant’ Grab WordPress Built-in Posts Through Loop
- How can my plugin display a populated new post window
- search content of pages and list in wp-admin
- Finding a post’s slug
- Insert specific information to a posts of a predefined category
- Open a wordpress single post in a lightbox without the header and footer
- show div only if have a related post inside
- marking a post that was sticky on category template
- WordPress: Develop multiple posts with different data
- How do I change the post title’s link on the posts page?
- Update user meta when post published no working
- Need help with hiding an image within a post in a category
- Fixing the WP Post Object for Custom Route
- Export Posts with specific custom fields by sql
- Custom plugin to get related posts by category
- Hide the contents for specific post
- Combining multiple conditional statements [closed]
- Error 404 blog/page/2/
- Onclick open posts displayed in slider in a popup [closed]
- How do I save JS classes being applied to the WP dashboard via custom plugin?
- Remove image caption from post excerpt
- Change WordPress post-state in Admin Area
- Guest Author – How to modify my custom function code if the guest author URL will follow a particular pattern/format?
- Working Bootstrap Carousel Conversion to WP – Technical Questions
- add image map script to post
- How to create shortcode to show the 2 latest posts
- Multiple authors for single post without plugin
- WordPress – Admin Manage Posts – Multiple Filters by Parent Category
- Author must complete profile info before they can publish a post?
- Advanced Custom Fields – Storing array value for further usage
- Check if post exists
- wp_query ‘s’ parameter does not work with custom post type
- WP Query – duplicated posts once including tags in search results
- View the number of entries recorded per day
- Transfer WordPress post to RoR site: is the REST Api the only and/or best solution?
- Alternate row and columns every X posts
- Duplicate posts and change category
- Removing noindex posts from wp_query
- Is there a PHP script to replace post date with updated modified date
- Post visibility based on user role
- Set static page/post from another blog on same network
- Add title for previous and next posts to Yoko Theme
- Add $values to post_class()
- Why are my paginated posts always returning the same results?
- Updating post meta for checkbox
- How do I limit the number of posts displayed to one?
- How do I switch css class on post
- Can’t save WordPress post with “/etc/” in it
- How to get post id of last approved comment?
- Trim posts from WP-Query?
- Remove subcategory slug from url
- Posting to WP via URL
- how can i take wordpress post as embed?
- Numbered Pagination Showing The Same Posts After Altering WP_Query
- WordPress Website is Auto-Posting strange posts
- How to count posts in tags within time limit
- delete post hook not being fired when deling in wordpress dashboard admin
- Manipulate query to show specific post
- alt of attached image in post / pages
- Display post in visual composer with custom html
- Hook To Get All Posts Deleted
- Have latest post and recent posts display differently
- How to get override the WP Admin Syndication feed limit for a custom feed?
- Adding Count Post in Page
- Custom post order returning posts from other categories
- How add class the_content();?
- Undefined Function Fatal Error with Shortcode [closed]
- How to sort posts alphabetically based on a specific parent category