?
Solved

Wordpress: search/replace when post saved

Posted on 2014-10-08
2
Medium Priority
?
203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

762 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