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?
- WordPress blog post tags in 2 rows
- redirect to uploaded (wordpress) post after form submission from front-end
- How can I get a table with the number of published posts by date?
- Only display sticky post or latest post in custom loop
- An array of latest wp_titles
- Display post category in foreach loop
- Single.php – Get Current Parent Category
- Order posts alphabetically: how to set order=asc in mysql query?
- How we exclude current post form related posts
- How to order posts in an arbitrary order?
- How to get date of post when using wp_get_recent_posts()?
- how can i change WP main archives loop to sort by name or title
- How to create a template for Pages?
- How do I stop the loop from repeating in my category template?
- Conditional for a Single Post That Belongs to a Category?
- Remove Content after
- Trying to alter the post_content through the_post
- Get post ID in post/page edit area
- get_the_category listing in hierarchial order
- Do all wordpress themes a similar class name for content?
- If statement to check if post has image
- Display Notification Bar on Header on Certain Post Count
- How to automate featured posts number? [duplicate]
- How do I do a page break?
- Is there a way to specify an extra class for a post or page with no title?
- Automatically create a new page daily with last three posts
- Using wp_list_pages() after calling query_posts()
- How do I manage my users post before publish?
- What do these phpMyAdmin errors mean on my WordPress databaes?
- Delete pubished and unpublished posts with wp_delete_post?
- How I can use order by of the custom post title?
- How to remove in-line style of WordPress’s post content only?
- How can I add content to a post that only shows in single-post mode?
- how to get post order by post id wp_query?
- Internal post link creates comments on its own
- Worpdress function for difference dates
- Is it possible to add/tick a category to a post when it is created?
- Insert sometext after first h3 in content
- When changing pages to posts, how do you set up 301 redirects for the page URLs?
- Excluding posts not working
- How many posts does the loop return?
- Avoiding “Missed Schedule” errors when inserting future posts
- Posts loop displaying the same post data
- Display Posts on Custom Page
- How to make a sum of all posts displayed in a loop
- How to include my own css in post
- Only show a Post once in 10 visits
- Shortcodes on my website stops working after theme update [closed]