WordPress.org

Support

Support » Plugins and Hacks » Hacks » Custom Post Text: Changing specific words in new posts

Custom Post Text: Changing specific words in new posts

  • Hey all,

    I have been looking into custom post templates, custom post types, dynamic post content, etc.. but I just cant seem to get this working. Any suggestions would be great. Thanks in advance.

    For example: Lets say I have a custom post template that has the following text in every post I make: The quick brown fox jumps over the lazy dog.

    Assuming I want to change the word “Fox” in the next 10 posts, how do I do this without editing the text area itself? The ideal situation would be to have a form field area where I can change just the specific words in my custom post template.

    Type of Animal 1: fox
    Type of Animal 2: dog
    Speed of Animal 1: quick

    Again, thanks in advance.

Viewing 1 replies (of 1 total)
  • Perhaps this code might help you to get a start..

    Copy the code into a new textfile and name it for instance my_plugin.php
    Upload it to your plugin dir and activate it.

    <?php
    /*
    Plugin Name: My Plugin
    */
    function my_function($text) {
    	$text=str_replace('fox','dog',$text);
    	return $text;
    }
    add_filter('the_content','my_function');
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Post Text: Changing specific words in new posts’ is closed to new replies.
Skip to toolbar