Solved

Wordpress: search/replace when post saved

Posted on 2014-10-08
2
194 Views
Last Modified: 2014-10-08
I want to put a snippet in my functions.php that will search/replace a string in $content as the post is saved.

I haven't been able to find any examples of that.

Can you show me how to do this?

Thanks,

Chris
0
Comment
Question by:St_Aug_Beach_Bum
2 Comments
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
ID: 40368796
It would look something like this:

function my_sanitize_content( $content ) {
    return str_replace( "Chris", "Jason", $content );
}
add_filter( 'content_save_pre' , 'my_sanitize_content' , 10, 1);

Open in new window


ref: http://codex.wordpress.org/Plugin_API/Filter_Reference/content_save_pre
0
 

Author Comment

by:St_Aug_Beach_Bum
ID: 40369283
That's the ticket :) Thank you!
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question