Forums

Page title as an instertable variable? (6 posts)

  1. thekevbot
    Member
    Posted 1 year ago #

    Hey guys, how can I insert a title of a given page into say a <h2></h2> tags?

    Say my navigation is News / About / Contact, where "News" is the homepage, and "About" and "Contact" are secondary single pages.

    Is there a php string I can insert in between some <h2> tags that will display the correct title of the page? "News" on news page, "about" on about page, etc.?

    All I can get it to display is the page_id, which as you are aware is just a number... :/

  2. zoonini
    help me help you
    Posted 1 year ago #

    This doesn't work?

    <?php the_title('<h2>', '</h2>'); ?>

    or

    <h2><?php the_title(); ?></h2>

    http://codex.wordpress.org/Function_Reference/the_title

  3. thekevbot
    Member
    Posted 1 year ago #

    No, that gives the title of the post, not the page. Is there a way to assign page title variables?

  4. zoonini
    help me help you
    Posted 1 year ago #

    Can you provide a link to your site?

    Do you mean the page slug?

    i.e. if the URL is mysite.com/kittens

    ...are you trying to get "Kittens" to show up as a heading on the page?

    I'm not sure I understand exactly what you're after.

  5. thekevbot
    Member
    Posted 1 year ago #

    Yes, that is essentially what I want to happen. Unfortunately, I can't provide you with a link as I'm under contract.

    Hopefully this will explain it better:

    When I type in the URL mysite.com, on the page that comes up, I want "news" to appear as an H2. If I click on the About page, or type in the URL mysite.com/about, I want "about" to appear as an H2. Of course, all this within WordPress. Does that make sense?

  6. alchymyth
    The Sweeper
    Posted 1 year ago #

    are you using page templates with a custom query?

    then try to use this before the custom query:

    <?php echo '<h2>' . $post->post_title . '</h2>'; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic