WordPress.org

Forums

Problem with get_page and [caption] shortcode (4 posts)

  1. najeeborg
    Member
    Posted 4 years ago #

    Hi there! I made a theme that use the content of a page. And I use get_page_by_title to do it. The problem is, it doesn't convert the short code [caption] into HTML.


    <div id="about">
    <?php $page = get_page_by_title('About'); echo $page -> post_content; ?>
    </div>

    This is what I mean (check About section) : http://afifnajib.com

  2. alchymyth
    Forum Moderator
    Posted 4 years ago #

    at least two possibilities:

    a:
    add do_shortcode() to the code:
    http://codex.wordpress.org/Function_Reference/do_shortcode

    <div id="about">
    <?php $page = get_page_by_title('About'); echo do_shortcode($page -> post_content); ?>
    </div>

    b:
    use apply_filters('the_content', .... )

    <div id="about">
    <?php $page = get_page_by_title('About'); echo apply_filters('the_content', $page -> post_content); ?>
    </div>
  3. najeeborg
    Member
    Posted 4 years ago #

    I tried the latter and it works. Thanks mate. :D

  4. vizou
    Member
    Posted 3 years ago #

    I'm having a similar problem but it involves jQuery tabs generated by getting child pages. Child page content appears just fine... except the page "gallery" that is using the built in WP [gallery] shortcodes. Any images placed normally (without captions) work fine, as does the jQuery tab script. when looking at source code, the shortcode doesn't appear at all.

    I've searched for hours for the answer and have narrowed it down to either a problem with the content variable or the query method which I'm not sure how to change in this situation. Seems that there needs to be a get_posts used somewhere but how?

    Page under construction is here.

    Here is my code; any help would greatly be appreciated :

    <!-- TABBED CHILD PAGES -->
    <ul class="tabs">
    
    <?php
    $pages = get_pages('child_of='.$post->ID.'&sort_column=menu_order&sort_order=asc');
    $content = $page->ID;
    $count = 0;
    foreach($pages as $page)
    {
    $count++;
    ?>
    
    <li><a href="#tab<?php echo $count ?>"><?php echo $page->post_title ?></a></li>
    
    <?php } ?>
    
    </ul>
    
    <!-- SUB-PAGE CONTENT -->
    <div class="tab-container">
    
    <?php
    $count = 0;
    foreach($pages as $page)
    {
    $content = $page->post_content;
    $count++;
    $content = apply_filters('the_content', $content);
    ?>
    
    <div id="tab<?php echo $count ?>" class="tab-content">
    <div class="post">
    <div class="entry">
    <?php echo $content ?>
    </div>
    </div>
    </div>
    
    <?php } ?>
    
    </div>

Topic Closed

This topic has been closed to new replies.

About this Topic