Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Simple title post WP question

Hi, I can't understand the difference between:

<title><?php wp_title(); ?> </title>

<?php echo get_the_title(); ?>

I hope someone can help me. I want to show the title of the page before the article. Which one should I use?

Edwin Goddard
Edwin Goddard
8,988 Points

Are you missing something from your question?

I don't really understand it. Do you want to know what the difference between the concepts of "and" and "or"?

4 Answers

Fixed now. I want to understand when I should use get_the_title and when to use wp_title.

wp_title - "filters the text appearing in the HTML <title> tag (sometimes called the "title tag" or "meta title"), not the post, page, or category title. "

In other words, using this places text in the <title> section of your .html, which translates to what you see as a tab title in a broswer (for example, this forum post appears as "Simple title post WP question" on my browser tab.)

get_the_title simply retrieves a post title.

I'm not completely clear on your question either - where do you want the title to appear? If you can answer that, then you'll know which one is more appropriate for this particular case.

alt text

I want to know when to use:

  1. the_title
  2. get_the_title
  3. wp_title