Solved

Wordpress: search/replace when post saved

Posted on 2014-10-08
2
183 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now