• 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… :/

Viewing 5 replies - 1 through 5 (of 5 total)
  • This doesn’t work?

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

    or

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

    http://codex.ww.wp.xz.cn/Function_Reference/the_title

    Thread Starter thekevbot

    (@thekevbot)

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

    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.

    Thread Starter thekevbot

    (@thekevbot)

    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?

    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>'; ?>

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Page title as an instertable variable?’ is closed to new replies.