i need replace words in my posts and saved new words after delete code in my functions
i use this code for replace
<?php
function replace_text_wps($text){
$replace = array(
// ‘WORD TO REPLACE’ => ‘REPLACE WORD WITH THIS’
'wp' => '<img href="#"><a href="#">wordpress</a>',
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
}
add_filter('the_content', 'replace_text_wps');
add_filter('acf/load_value/name=artist', 'replace_text_wps');
?>
this code is ok and replaced my words but if delete this code in my functions new words not saved
i want one time replaced all words and save and delete code
how to that this ?
sorry , i can't good speaking english
i need replace words in my posts and saved new words after delete code in my functions
i use this code for replace
<?php
function replace_text_wps($text){
$replace = array(
// ‘WORD TO REPLACE’ => ‘REPLACE WORD WITH THIS’
'wp' => '<img href="#"><a href="#">wordpress</a>',
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
}
add_filter('the_content', 'replace_text_wps');
add_filter('acf/load_value/name=artist', 'replace_text_wps');
?>
this code is ok and replaced my words but if delete this code in my functions new words not saved
i want one time replaced all words and save and delete code
how to that this ?
sorry , i can't good speaking english
For a one-time "patch" to update your database for word replacement, I find that this tool from interconnectit.com is excellent. Be sure to have a backup of your database first, just in case.
An alternative would be to write a plugin that pulls the content from each post, does the filter, then updates the post by saving it back to the database. Your code is only filtering the content when it is being displayed, you are missing the steps of actually modifying the content and saving it again.
The DB-level word replacement routine is much more efficient, especially if this is a one-time event. The tool will allow you to target specific tables, so you don't inadvertently change text in other than the _posts
table.