• Hi, I has been trying to display a parent page permalink on child page in two ways and I’m unsuccessful in both:
    1) <?php
    $parent_link = get_permalink($page->page_parent);
    echo $parent_link;
    ?>

    in this way it displays the page itself link but not the parent page;

    2) ?<php
    $parent = get_page($page->page_parent);
    echo $parent;
    ?>
    in this way I get:
    Catchable fatal error: Object of class stdClass could not be converted to string.

    I can’t understand why I do not get parent page (not post) link. Help pls.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Using method #2, get_page( $page->page_parent ); returns an object.

    So, to get the ID out of $parent, you will need to use:

    $parent->ID

    Try something like:

    $parent = get_page( $page->page_parent );
    $parent_id = $parent->ID;
    $parent_link = get_permalink( $parent_id );
    echo $parent_link;

    Thread Starter albern

    (@albern)

    Thank you for replying to my post.
    I tried this and I get the page itself link, not the parent page link.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Fatal Error while trying to get parent page permalink’ is closed to new replies.