Apply filters to get_the_content() (7 posts)

  1. SteeleR
    Posted 6 years ago #

    I need to get the content of a page and not echo it. I.e. The the_content echoes the page content but using get_the_content() skips the applying of the filters so the plugins that are installed do not work. My question is how do I apply the filters to the get_the_content() function. I've tried:

    apply_filters('the_content', get_the_content);
    $panels = explode("[newpage]", get_the_content());

    but it's not working...

  2. SteeleR
    Posted 6 years ago #

    mmm.. found the solution:

    $content = get_the_content();
    $content = apply_filters('the_content', $content);
    $panels = explode("[newpage]", $content);


  3. Zoinks! Graphics
    Posted 6 years ago #

    Fantastic! Thanks for sharing. :)

  4. Robert
    Posted 6 years ago #

    Wow, just what I was looking for! Thanks for sharing :D

  5. jonradio
    Posted 6 years ago #

    I, too, researched this back in May. But what I found was a little different:

    // from http://www.web-templates.nu/2008/08/31/get_the_content-with-formatting/
    	$content = get_the_content();
    	$content = apply_filters('the_content', $content);
    	$content = str_replace(']]>', ']]>', $content);

    I'm not saying that SteeleR's won't work.

  6. jtwg
    Posted 6 years ago #

    Another approach:

    $content = ob_get_clean();
  7. jonshipman
    Posted 6 years ago #

    I am new to wordpress, but I've found that I need to use this code! :D

    However, putting the OP's code in page.php or functions.php within my theme's folder does nothing. How would one go about using this code?

    Right now my page code looks like this:

    		if (have_posts()) : while (have_posts()) : the_post(); ?>
    				<?php echo get_the_content(); ?>
    				<?php wp_link_pages(array('before' => '', 'after' => '', 'next_or_number' => 'number')); ?>
    		<?php endwhile; endif; ?>

    which works great, except for plugins aren't working when I add them to a page. Any help would be most appreciated.


Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.