WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Text: Changing specific words in new posts (2 posts)

  1. lownice
    Member
    Posted 2 years ago #

    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.

  2. Threecows
    Member
    Posted 2 years ago #

    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');
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.