• Hello,

    I’m trying to figure out how i can place a variable in the content of my posts that is replaces on the fly when accessed via the RSS feed.

    So for example, if the post body were:

    “I am #####’s post body.”

    Then via an RSS url such as site.com/feed/bobby/ the content of the post body would print out like:

    “I am bobby’s post body.”

    (##### is replaced with the value “bobby”)

    Any input would be appreciated. thank you.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter zigx

    (@zigx)

    if anyone has ANY related info on this i would love to read it. i have searched the forums but couldn’t find anything on point with what im looking to do.

    thank you.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    What is “bobby” in this case? Replacing text is easy, the real question is what are you replacing it with? Unless you know where to get “bobby”, there’s no way to tell you how to do it.

    Thread Starter zigx

    (@zigx)

    otto thank u for responding!

    basically “bobby” is a string that the feed will use to replace a “place holder” string within the post’s content.

    So it could look like site.com/feed/?name=whatever OR site.com/feed/whatever/

    And when someone uses the feed, content will be generated and on the fly anywhere within the content “#####” is found, it is replaced with “whatever” .

    zigx: I’m not sure how much PHP/etc. you understand but the two things you’re looking for are $_GET[”] vars and the str_replace() function.

    Basically, before the feed is sent (find this in the source), include the line:

    $rss = str_replace(“%name%”, $_GET[‘name’], $rss);

    Where $rss is the variable currently holding the rss feed data. Anywhere that %name% appears it will be replaced with the ?name=xxxx content on the request URL.

    More information on str_replace()

    Hope that helps.

    Thread Starter zigx

    (@zigx)

    mutube that is exactly what i was thinking needed to be done… BUT, ?? , line 45 of wp-rss2.php says:

    <content:encoded><![CDATA[<?php the_content() ?>]]></content:encoded>

    “the_content()” is a function… how do i apply the replace on a function like that???

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    WordPress has the concept of “filters”. A filter works like this:

    function replace_name_tag_rss($content)
    {
    if (is_feed())
    {
    $content = str_replace("%name%", $_GET['name'], $content);
    }
    return $content;
    }
    add_filter('the_content','replace_name_tag_rss');
    Thread Starter zigx

    (@zigx)

    wow man thank you so much.

    I will read up on filters and try to figure out where i actually need to store that function.

    I really appreciate you taking the time to actually code that up.

    did a plug in or solution come out of this? i need a way to replace text with a file or include another post.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘RSS: Replace Specific Text in Content with Variable?’ is closed to new replies.