Support » Plugins » Shortcodes in posts that are displayed in page templates

  • I friend who has a large number of sales landing pages, each with a unique intro and a shared main content body. I’ve made the management of these easier by creating a bunch of templates as follows: Each template pulls in a unique post for the introduction, and then pulls in another common post for the main body. This works great, except when it comes to running plugin shortcodes in either of the posts that are queried and displayed in a template. The shortcodes work when viewing the actual post, but when you view the page that uses the template that queries and displays this post, the shortcodes fail.

    Specifically, I need to make it so he can use shortcodes to embed a video using a video player plugin.

    I was thinking of adding a plugin to allow PHP in posts/pages and then instructing my friend to wrap each shortcode in do_shortcode().

    This just seems messy. Are there any other ways of doing this? Thanks for any advice.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Here is the solution:

    Instead of querying posts like this:

    $post_id = 13;
    $queried_post = get_post($post_id);
    echo $queried_post->post_content;

    Do it like this:

    $query = new WP_Query(‘p=13’);
    <?php the_content();?>
    <?php endwhile; ?>`

    in the ‘get_post()’ code, you could also possibly try:

    echo apply_filters('the_content', $queried_post->post_content);
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Shortcodes in posts that are displayed in page templates’ is closed to new replies.