[WordPress] How to display the page title and how it should be displayed
This is a story about how to display page titles and how they should be displayed.
First, I would like to list some ways to display page titles in WordPress.
How to display [blog name]
<title><?php bloginfo('name'); ?></title>
'name' is the 'site title' set in 'Settings > General' on the administration screen.
via: Template tag/bloginfo - WordPress Codex Japanese version
How to display [Page title]
<title><?php wp_title(''); ?></title>
To display the page title in WordPress, a template tag called wp_title is used, which is a very flexible and convenient tag.
use box sizing property for align the size of the form items
- When viewing an individual page or article, display its title
- Display date when viewing archive page
- Display category when viewing category page
- Show tags when viewing tag page
- Display the author when viewing the author page
It will display each one like this.
How to display [Blog name | Page title]
To display the combination of blog name and page title as [Blog name | Page title], write as follows.
<title><?php bloginfo('name'); ?><?php wp_title(' | '); ?></title>
Or you can write it as follows.
<title><?php bloginfo('name'); ?><?php wp_title(' | ',true,''); ?></title>
Put ' | ' inside the parentheses of wp_title to separate it with a vertical bar.
I think you can use characters other than vertical bars to separate them.
How to display [Page title | Blog name]
To bring the page title to the top, write as follows.
<title><?php wp_title(' | ',true,'right'); ?><?php bloginfo('name'); ?></title>
Adding 'right' inside the parentheses of wp_title moves the separator line to the right.
What happened to this blog?
As a result of various considerations based on the above, this site displays only [Page Title] for single article posts (single.php), and [Page Title | Blog Name] for other posts.
In the past, I blindly posted single articles using [page title | blog name], but I thought that for blogs, I could increase the SEO effect by using only [page title]. Ta.
Afterword
I briefly discussed how page titles should be displayed and how they should be displayed.
I don't know if you have the same idea as me, but there were quite a few famous blogs that only used [page title] when posting a single article.
I would like to measure the effect and verify it for a while.
[Related]: [WordPress] How to remove the space at the beginning of wp_title