functions - How to replace words in my posts and saved new words

admin2025-01-07  4

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

Share Improve this question asked Oct 11, 2016 at 11:42 alam7oalam7o 317 bronze badges 2
  • Is this a one-time thing you want to do, or is it a function you need to use over again on a regular basis? – C C Commented Oct 11, 2016 at 11:49
  • @CC just on-time , and after replaced words i want delete this code in functions – alam7o Commented Oct 11, 2016 at 11:57
Add a comment  | 

1 Answer 1

Reset to default 0

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736265400a1042.html

最新回复(0)