Skip to content

Instantly share code, notes, and snippets.

@nyxsandbox
Created September 30, 2012 23:11
Show Gist options
  • Select an option

  • Save nyxsandbox/3808695 to your computer and use it in GitHub Desktop.

Select an option

Save nyxsandbox/3808695 to your computer and use it in GitHub Desktop.
Wordpress: Automatically Replace Words in Posts
function replace_text_wps($text){
$replace = array(
// 'WORD TO REPLACE' => 'REPLACE WORD WITH THIS'
'wordpress' => '<a href="#">wordpress</a>',
'excerpt' => '<a href="#">excerpt</a>',
'function' => '<a href="#">function</a>'
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
}
add_filter('the_content', 'replace_text_wps');
add_filter('the_excerpt', 'replace_text_wps');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment