• 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…

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter steeler

    (@steeler)

    mmm.. found the solution:

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

    ??

    Fantastic! Thanks for sharing. ??

    Robert

    (@robertgrinde)

    Wow, just what I was looking for! Thanks for sharing ??

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

    // from https://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.

    Another approach:

    ob_start();
    the_content();
    $content = ob_get_clean();

    I am new to wordpress, but I’ve found that I need to use this code! ??

    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

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Apply filters to get_the_content()’ is closed to new replies.