Get parent page title?

Community Forums Forums General Discussion Get parent page title?

This topic is: not resolved

This topic contains 3 replies, has 2 voices, and was last updated by  Posh John 8 months, 4 weeks ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #70526

    Posh John
    Participant
    Post count: 42

    I’ve created a page template and need to add the parent page’s title.

    I tried adding this:

    //* Add Title Bar
    add_action( 'genesis_before_entry_content', 'cw_title' );
    function cw_title() {
    	$parent_title = get_the_title( $post->post_parent );
    	echo '<h1>Directory Of Locations In ' .$parent_title. '</h1>';
    		
    }
    

    It just echoes the current page title, not the parent page title – any ideas why?

    (also i’d ideally like to make the variable $parent_title available to other functions…)

    Thanks


    Thus the heavens and the earth were completed in all their vast array. Genesis 2

    http://development site
    #70568

    nutsandbolts
    Moderator
    Post count: 3113

    Just to verify, you’re using one of the newer, HTML5-compatible child themes, right? If not, the genesis_before_entry_content hook won’t work. I’m sure the answer isn’t that simple, but I like to start with the easiest possibility first. :)


    Andrea Whitmer, Owner, Nuts and Bolts Media
    I provide dev and training services for web designers • Find me on Twitter and Google+

    #70576

    Posh John
    Participant
    Post count: 42

    Hi,
    Yes i am using HTML5. The problem is not with the hook, it’s just the fact that it’s picking up the page title and not the parent page title.
    I checked the codex and my code should work….?


    Thus the heavens and the earth were completed in all their vast array. Genesis 2

    #70685

    Posh John
    Participant
    Post count: 42

    I figured it out so i thought i’d add it here just in case anyone else needs to know.

    I just needed to add global $post;


    Thus the heavens and the earth were completed in all their vast array. Genesis 2

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.