Support » Fixing WordPress » How to get the parent page permalink

  • Hi,

    When I’m in a subpage I’m getting the parent page title using something like that:

    $parent_title = get_the_title($post->post_parent); echo $parent_title;

    I’m looking for a tip to link the parent title with the parent page permalink.

    Thanks in advance!

Viewing 6 replies - 1 through 6 (of 6 total)
  • I don’t see the way to get the permalink using get_page_by_title, Could you plese be more specific?


    $parent = get_page_by_title($parent_title);
    $parent_link = '<a href="'.$parent->guid.'">'.$parent_title.'</a>'

    @esmi Thanks but it’s not working…the output is nothing. Else if I do not include the php starting and closing tag and just write guid.'”>’.$parent_title.’‘ I get the correct parent url but unfortunately it’s got the ‘.$parent_title.’ attached to the end of it rendering it a broken link.

    Try this:

    <?php $permalink = get_permalink($post->post_parent); ?>
    <a href="<?php echo $permalink; ?>"Parent</a>

    I used the code that PSound gave, though please note it needs one fix for a typo:

    <?php $permalink = get_permalink($post->post_parent); ?>
    <a href="<?php echo $permalink; ?>">Parent</a>

    Thanks, PSound!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to get the parent page permalink’ is closed to new replies.