WordPress.org

Support

Support » Plugins and Hacks » [Resolved] How to change text string to another string?

[Resolved] How to change text string to another string?

  • Hello
    This is my plugin code:

    function my( $content ) {
    $contenttt = str_replace("abc", "AAAAAAAAA", $content);
    return $contenttt.'BBBBBBBBB';
    }
    add_filter('the_content', 'my');

    But this script only add ‘BBBBBBBBB’ to my post.
    What I must to write in this plugin when I will replace string “abc” in all posts??

Viewing 9 replies - 1 through 9 (of 9 total)
  • Make sure “abc” is in the_content? Technically the code looks OK to me.

    I’m sure.
    Now I write in plugin this code:

    function my( $content ) {
    echo 'BBBBBB';
    }
    add_filter('the_content', 'my');

    But when I activate plugin and write post: ‘text text text text text’, I see ‘text text text text textBBBBBB’
    What I must to write in this plugin when I will see only ‘BBBBBB’ ?

    Don’t echo. It’s a filter. Stuff goes in the top and comes out (modified, or the same) the bottom. No side effects (well, you can do them but it’s ill-advised). End with a return statement.

    Replace echo with return "foo"; and you should only see ‘foo’

    This is my plugin code:

    function my( $content ) {
    $contenttt = str_replace(“abc”, “AAAAAAAAA”, $content);
    return $contenttt.’BBBBBBBBB’;
    }
    add_filter(‘the_content’, ‘my’);

    But this script only add ‘BBBBBBBBB’ to my post.
    What I must to write in this plugin when I will replace string “abc” in all posts??

    I don’t know if this was your problem, but you defined the variable $contenttt and then returned $content . ‘BBBBBBBBB’.

    In this case, $content would have been returned empty.

    ok. now I have:

    function my( $content ) {
    return "foo";
    }
    add_filter('the_content', 'my');

    But this does not solve the problem :/

    Look here: http://www.uniaeuropejska.net/
    There is (in posts) something like:
    text text text
    link
    “foo”
    But i will only “foo”

    please help.

    I’m not quite sure what you’re trying to do… so please explain. And if you can, post “the loop” from the template that is generating that page.

    Your filter above should replace the entire contents of the_content with the word “foo” anytime the_content() is used. It won’t affect anything else. and if your template is taking the data from the database without using the WordPress template tags, you’ll need to change the template.

    I want to replace the content of the post from database with another text string.

    In this string i will change something in orginal content of the post from database.

    Unfortunately, str_replace() doesn’t work, echo “foo” and return “foo” as well.

    If you’re using the filter you defined, and that’s where the “foo” comes from, then something else other than the_content is generating the rest of the text. Perhaps a later filter?

    You’ll need to post a bit more info than that.

    You were right
    Another plugin generate the_content and when I repair this it’s working.

    thanks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Resolved] How to change text string to another string?’ is closed to new replies.
Skip to toolbar