I'm building a theme for a friend but some some reason I can't get shortcodes to work in Pages. They only work in Posts.
My page.php file is very simple at the moment:
<?php get_header(); ?>
<?php
if (have_posts()) :
while (have_posts()) : the_post();
echo '<div class="hero-unit"><div class="container"><h1>'.get_the_title().'</h1></div></div>';
echo '<div class="container clearfix" id="main-content">'.get_the_content().'</div>';
endwhile;
endif;
?>
<?php get_footer(); ?>
This is working fine but is just displaying the shortcode as text. IE I am trying to use the shortcode [wp_sitemap_page] the page just renders '[wp_sitemap_page]' in text.
What could be the issue?
Your post content is displayed via echo get_the_content()
which is a function that returns the content WITHOUT applying the default filters (wpautop
, do_shortcode
etc) that are applied normally when you use the_content()
instead.
This should fix it:
<?php
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<div class="hero-unit"><div class="container"><h1><?php the_title(); ?></h1></div></div>
<div class="container clearfix" id="main-content"><?php the_content(); ?></div>
<?php endwhile;
endif;
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With