WordPress.org

Ready to get started?Download WordPress

Forums

How to get the parent page permalink (7 posts)

  1. alturo
    Member
    Posted 5 years ago #

    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!

  2. esmi
    Forum Moderator
    Posted 5 years ago #

  3. alturo
    Member
    Posted 5 years ago #

    I don't see the way to get the permalink using get_page_by_title, Could you plese be more specific?

    Thanks!

  4. esmi
    Forum Moderator
    Posted 5 years ago #

    $parent = get_page_by_title($parent_title);
    $parent_link = '<a href="'.$parent->guid.'">'.$parent_title.'</a>'
  5. mariostella
    Member
    Posted 5 years ago #

    @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.

  6. PSound
    Member
    Posted 4 years ago #

    Try this:

    <?php $permalink = get_permalink($post->post_parent); ?>
    <a href="<?php echo $permalink; ?>"Parent</a>
  7. scormeny
    Member
    Posted 4 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic