WordPress.org

Ready to get started?Download WordPress

Forums

Apply filters to get_the_content() (7 posts)

  1. SteeleR
    Member
    Posted 4 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
    Member
    Posted 4 years ago #

    mmm.. found the solution:

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

    :)

  3. Zoinks! Graphics
    Member
    Posted 4 years ago #

    Fantastic! Thanks for sharing. :)

  4. Robert
    Member
    Posted 4 years ago #

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

  5. jonradio
    Member
    Posted 4 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
    Member
    Posted 4 years ago #

    Another approach:

    ob_start();
    the_content();
    $content = ob_get_clean();
  7. jonshipman
    Member
    Posted 4 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:

    <?php 
    
    		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.

    -Jon

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.