Is there à code to replace words?

Status
Not open for further replies.

elma22

Banned
Banned
66
2013
4
0
Hello,

i have a website. I want to put in à php file à code which van replace words of that word exist

is there simple code which i can add to my php file?

i dont understand those codec at google
 
4 comments
ok that was what i mean, i dont understand those kind of pages

i want to put a code in single.php of my wordpress site. and if a post get posted with those words it must replace it

i dont want to use a plugin, i want a code which i can put in single or functions.php or where? is there a code ?
 
add below in your functions.php and change words accordingly in $replace array.

PHP:
function replace_words($text){   
 $replace = array(                    
'wordA' => 'replacewithwordA',                   
 'wordB' => 'replacewithwordB',                
 'wordC' => 'replacewithwordC'                  
  );           

 $text = str_replace(array_keys($replace), $replace, $text);            
return $text;    
}

add_filter('the_content', 'replace_words');
add_filter('the_excerpt', 'replace_words');
 
Last edited:
thnx sir, so like this right?


function replace_words($text){
$replace = array(
'porn' => 'p**n',
'warez' => 'w**z',
'hack' => 'ha***'
);

$text = str_replace(array_keys($replace), $replace, $text);
return
$text;
}

add_filter('the_content', 'replace_words');
add_filter('the_excerpt', 'replace_words');
 
Status
Not open for further replies.
Back
Top