The Best way to replace words in your posts


Sponsored Links




Like we all know, WordPress is the most promising publishing platform, it’s free and easy to tweak or installed new themes or plugin. Or if we have little bit knowledge in PHP Programming we can enhanced our WordPress more easily. On this example from WPSnipp, we will show you How To Replace Words in Your WordPress posts easily.

Replace Word on WordPress Content

Replace Word on WordPress Content

This tutorial need to edit your functions.php, because this code do some add_filter to make it works.

All need to do, open your functions.php and paste this code.

function replace_text_wps($text){
    $replace = array(
        // 'WORD TO REPLACE' => 'REPLACE WORD WITH THIS'
        'wordpress' => '<a href="#">wordpress</a>',
        'domain' => '<a href="#">domain</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');

On the code above using add_filter to filter the_content and the_excerpt. So all match words will be replace with the new parameter as described. That’s is, we hope this tutorial works on you. Thanks Kevin Chard from WP Snipp for this code

Images from http://www.flickr.com/photos/42931449@N07/5418402840/

Subscribe to Full RSS Feed

RSS FeedIf you thing this article useful, please consider subscribing to our RSS Feed or e-mail updates and stay updated with us. You can also follow @WPTricksNet on twitter for latest updates.

About WP Tricks

We are WordPress Family, we collected and writed useful tips and tricks for you WordPress. We share it for you...

Related Tips and Trick from Local Data and on The Net


One Response to The Best way to replace words in your posts

  1. Pingback: The Best way to replace words in your posts | Jhez3R

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>