Get the Page Content,without generating HTML

I want to get the page content (so i can parse the tags/short-codes in it), but i don’t want to output the result itself to the browser (i.e. echo=0).

I tried get_the_content(); but its the same deal.

Related posts

Leave a Reply

3 comments

  1. Where are you doing your code parsing? If you’re doing it directly in the template file, inside the Loop, then you should be using get_the_content().

    However, it might be more efficient to filter the_content(), via the the_content filter. e.g. in functions.php:

    function mytheme_filter_the_content( $content ) {
        // add code here to filter the_content
        // which is contained in the $content variable,
        // then return $content
        return $content;
    }
    add_filter( 'the_content', 'mytheme_filter_the_content' );
    

    EDIT

    If, for whatever reason, you just want to parse the_content(), pull out the shorcodes, and execute them, use do_shortcode() (Codex ref). e.g.:

    <?php
    $page_content = get_the_content();
    $page_shortcodes = array() // ...some array that includes whatever shortcodes you found
    
    foreach ( $page_shortcodes as $page_shortcode ) {
        do_shortcode( $page_shortcode );
    }
    ?>
    
  2. <?php  
             query_posts( 'type=post&posts_per_page=1' );
    
               if ( have_posts() ) : while ( have_posts() ) : the_post();
    
               ?> 
    
                 <?php the_content(); ?>
    
                 <?php endwhile;
                                   endif; 
    
                  wp_reset_query();
                  ?>