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 usethe_content()
instead.This should fix it: