Echo the subtitle of a PARENT page within WordPress?

  • Unknown's avatar

    I’m attempting to fetch the subtitle from the PARENT page and echo the text within a title tag.

    Function:

    <?php
        $id_to_get = $post->ID;
        if ( $post->post_parent ) {
            $id_to_get = $post->post_parent;
        }
        $parent = $id_to_get;
    
        $title = get_the_title($parent);
        $subtitle = get_post_meta($id_to_get, '_base_page_subtitle', true);
    ?>

    HTML Implementation:
    ...title="<?php echo $subtitle; ?>">

    Unfortunately, it is not successfully grabbing the subtitle text. I’m able to populate the title echoing the variable $title, just not with the variable $subtitle.

    The value for the Subtitle option is stored within the table “_base_page_subtitle”; I’m using options framework.

    I know my issue is with the if statement, however, being new to PHP, I’m having a bit of difficulty figuring out how to capture the data and display it properly.

    Thanks again of time!

  • Unknown's avatar

    You did not specify a blog address or reason for posting when you created this topic.

    This support forum is for blogs hosted at WordPress.com. If your question is about a self-hosted WordPress blog then you’ll find help at the WordPress.org forums.

    If you don’t understand the difference between WordPress.com and WordPress.org, you may find this information helpful.

    If you forgot to include a link to your blog, you can reply and include it below. It’ll help people to answer your question.

    This is an automated message.

  • The topic ‘Echo the subtitle of a PARENT page within WordPress?’ is closed to new replies.