Cpawl
Cpawl

Reputation: 95

Using WordPress shortcodes when <?php echo getPageContent(); ?> is used to display content

I am working on a single page site where I am displaying content from other pages on this single page. To do this I added a function that allows me to use <?php echo getPageContent(ID); ?> this is working fine except when I need to display content from a shortcode it just spits back the code as text instead. Any idea of a work around?

Upvotes: 0

Views: 1626

Answers (2)

Richard M
Richard M

Reputation: 14543

To get the correct formatting and to have shortcodes replaced you need to apply the filters hooked into the the_content tag, something like this:

echo apply_filters('the_content', getPageContent(ID));

Upvotes: 4

spuriousdata
spuriousdata

Reputation: 573

Is there a reason that you've chosen this strategy to display the content? Using something more in line with the normal wordpress page development and templating system will likely fix your problem. I recommend using a combination of get_posts() and setup_postdata()

From WordPress' docs:

<?php
global $post;
$tmp_post = $post;
$args = array( 'numberposts' => 5, 'offset'=> 1, 'category' => 1 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
<?php $post = $tmp_post;
?>

See: http://codex.wordpress.org/Template_Tags/get_posts

Upvotes: 0

Related Questions