• Rys

    (@ryn_90)


    Hi Guys,

    I would like to know how to get the name of the page and display it in the html. So I will create the headers automatically from the name of the page.

    I tried this, but it didn’t work:
    <h1> <?php echo get_the_title(ID) ?> </h1>

    Thanks for your help.

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter Rys

    (@ryn_90)

    Ok now I’ve found this: <?php wp_title(); ?> and it works. How do i remove the “?”

    esmi

    (@esmi)

    Thread Starter Rys

    (@ryn_90)

    Oh thanks missed that, this works for those who would like to know how: <?php wp_title(''); ?>

    Chip Bennett

    (@chipbennett)

    What about using:

    <?php the_title(); ?>

    Thread Starter Rys

    (@ryn_90)

    Hi again Chris,

    This gives the same result as <?php wp_title(); ?> because I tried it, I’m not sure which is best

    Chip Bennett

    (@chipbennett)

    wp_title() is intended to be output in the <title> tag in the document head, and is quite often filtered to output considerably more than just the Page/Post Title.

    the_title() is intended to be output in the document body, and will always only be the Page/Post Title.

    Thread Starter Rys

    (@ryn_90)

    So when I need an <h1> I will use wp_title();

    Chip Bennett

    (@chipbennett)

    So when I need an <h1> I will use wp_title();

    Generally speaking, wp_title() should only be used to output the <title> tag in the document head.

    Thread Starter Rys

    (@ryn_90)

    so I use the_title() for the h1?

    Chip Bennett

    (@chipbennett)

    so I use the_title() for the h1?

    Exactly!

    And you can use it anywhere in the document body (i.e. within the <body> tags) that you want to output the Page/Post Title, not necessarily only within the <h1> tags.

    Thread Starter Rys

    (@ryn_90)

    Yeah I understand, but in this case I need to auto generate all the <h1> in the website.

    Chip Bennett

    (@chipbennett)

    Gotcha; then the_title() is the template tag to use!

    djsounds02

    (@djsounds02)

    I want the page name on a title bar I have above the content yet it only gives me the name of the first post?

    Thread Starter Rys

    (@ryn_90)

    This works to get the page name, I use it in the Meta Title too: <?php wp_title(); ?>

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘How to get the name of the Page’ is closed to new replies.