Reputation: 4234
My homepage's title is being displayed as the title of the last blog post created.
The code is:
<title><?php bloginfo('name'); ?></title>
So from my understanding that should display the blog title (set in general settings) on the homepage.
But its not. Its displaying the most recent post title.
What do i need to look for?
Upvotes: 0
Views: 949
Reputation: 2249
I found your problem! Error in your code : remove >
after <?php
(you have written <?php>
) so this :
<?php> bloginfo('name'); ?>
should now become this :
<?php bloginfo('name'); ?>
And it will work !
Upvotes: 0
Reputation: 2249
wp_title()
is used to display the title of the page being displayed, but it uses the query results to get its value. So if you are executing a loop on many posts (which you obviously are on your homepage) and you don't reset it, you will get the title of the last post in your loop... logical.
Besides, note that the homepage is index.php in your theme, it is not a real page in WordPress. So it hasn't got a title. So wp_title()
can't be of any use for you here.
Basically, your homepage has not got any title. So if this template is both for your homepage and other pages, you need to do a conditional check :
Is this homepage? (use is_home()
)
A. Yes, echo "Welcome on my great website"
B. No, wp_title(), which will echo the title of the page you are on...
Do you get it?
Upvotes: 1
Reputation: 498
First off, you're executing two functions here -- wp_title, which retrieves the title of the page the visitor is currently on, and thereafter bloginfo, which with the argument 'name' indeed fetches your blog's name as set in the configuration.
However, there's a slight error in your code; you'd get the desired result as follows:
<title>
<?php
wp_title('|', true, 'right');
bloginfo('name');
?>
</title>
You should read about the parameters for wp_title
on the WP Codex; the | gives you a delimiter, for example, and 'right' tells the function where to output said separator.
Note: I'd advise you to display both the post title and blog name, as only the blog name on every single page is both unhelpful for visitors and yields por results in search engine results.
Upvotes: 0