Support » Fixing WordPress » Howto get substring of the_content() ???

  • Hi there,

    I’ve been playing with WP for some time, currently trying to use it for some college website. And what I need is to get substring of the_content().

    I guess it echo’s the string within the function, is there a way to get the content returned, rather than echoed out?!

    Read the documentation, searched the support forums, but nothing came up!

    Thanks in advance…

Viewing 6 replies - 1 through 6 (of 6 total)
  • What are you trying to do? Perhaps there is another solution to the one you are considering.

    Hi manstraw,

    Thanks for your reply. I was trying to get the contetn of the post to some php variable. Using the_content() echo’s it straight away and there is no way of playing with it.

    However, I found a workaround. I queried the DB and got everything I wanted in an array 🙂

    This article in codex was very helpfull.

    Thanks yet again…

    Use $post->post_content or a filter.

    My appologies for being so late.

    Gosh, I should have spent more time looking for that class…

    Thanks Viper007Bond.

    I want to store the output of the_content in a PHP variable as well. However, I don’t think I can use post->post_content because I need the code to be HTML – (so it includes the
    tags and <p> tags and stuff). Is there any way to store that code in a variable?

    eg- either have post->post_content output as HTML
    or- store the_content in a variable


    ok so I figured it out. For anyone trying to do this in the future….

    Open the file “wp-includes/template-functions-post.php”
    On line 74 or so there is a function called “the_content”
    Copy that whole function and paste it below
    Rename it to something like “the_content_modified”
    Change the line that reads “echo $content;”
    To “return $content;”

    Now you can store it in a variable using:
    $myVariable = htmlspecialchars (the_content_modified(”, 0, ”));

    *this example will keep all the HTML tags


Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Howto get substring of the_content() ???’ is closed to new replies.