How to realize different titles on different pages in the development of WP website? 2 ways to solve the # learning wave plan #, what is wp

1 year ago (2023-12-06) Chief Editor
4 minutes
two hundred and seventy-one
zero

For a WordPress website, its front page is ever-changing, and different pages must have different content and titles. If all the pages of a WordPress website have the same title, it is very unfriendly to search engines. So, in During the development of wordpress website theme template, how to realize different pages calling different titles This is not difficult. We can do it in two ways.

Method 1: Through judgment, different pages of the wordpress website call different titles.

Wordpress provides judgment functions for template pages. We can use these functions to judge the current page, and then call these page title functions. For example, the category page calls the category page title function; The article page calls the article page title function. The codes are as follows:

If (is_home()) {//If it is the first page, call the first page title

bloginfo(name);

}Elseif (is_single() | | is_page()) {//If it is an article detail page or a single page

the_title(); // Title of the article and page

echo " - ";

bloginfo(name);

}else{

single_cat_title(, false); // Category directory and title of tag page

echo " - ";

bloginfo(name);

}

Through the above judgment, we can achieve: Wordpress website The home page directly displays the title of the home page; If it is a single page of articles and pages, use the_title() to call their titles; For the category and tag tabs, use single_cat_title() to call their titles.

Method 2: Use the title function wp_title() of wordpress to implement.

Wp_title() is wordpress The provided website title function can call the corresponding title on other website pages except the homepage of the website, which also achieves the effect of method 1. Let's look at this function first.

wp_title( $sep, $display, $seplocation );

From the above code, we can see that the wp_title() function can have three parameters:

$sep: string type data, optional. Here is the separator for the front page title of the wordpress website. The default value is ». If you want to use other separators, you can use this parameter$ Display: Boolean data type, optional. This parameter means whether to print the title to the page. The default value is true, indicating display. If you only want to assign values to variables, you can set it to false$ Seplacation: string type data, optional. The function of this parameter is to display the separator on the left by default. If you want to display the separator on the right of the title, you can set it to right.

Case:

<? php

wp_title(" - ",true,right);

bloginfo("name"); echo " - ";

bloginfo("description");

?>

When the wp_title() is on the home page, it will not display any content because the data cannot be called; And it is in the rest of the wordpress website Template The page can play a role. The article title will be called on the article template page, the page title will be called on the page single page template page, the classification directory title will be called on the website classification page, and the tag title will be called on the tags page. That is to say, wordpress is already done inside the wp_title() function Site Template Then, call the titles of different pages according to different website template pages.

If you like my article, please click the "Follow" button to follow me. I will publish new content regularly every day. These are my views. If you have different views, please comment.

This article is written by: Chief Editor Published on Software Development of Little Turkey , please indicate the source for reprinting: //hongchengtech.cn/blog/1961.html
Kuke_WP editor
author

Related recommendations

1 year ago (2024-02-20)

What technologies have been applied and developed in the field of new media, and the application of new technologies in media

In the field of new media, many technologies have been applied and developed. These include: cloud computing: cloud computing technology enables new media companies to develop and deploy applications more quickly, and can dynamically adjust resources according to needs. Big data: New media companies can use big data technology to analyze massive user data, understand user preferences, behavior habits and other information
nine hundred and seventy-one
one
1 year ago (2024-02-20)

WMS warehouse management system, promoting the transformation of warehousing from extensive to fine management, WMS warehouse management

Warehousing is extremely important for the manufacturing industry and is an important guarantee for the survival and development of manufacturing enterprises. However, with the expansion of manufacturing enterprises' business, the traditional warehouse management has been unable to respond to business changes quickly. The extensive management mode not only makes the warehouse operation not smooth, but also increases the storage cost. Therefore, it is necessary for manufacturing enterprises to deploy a WMS warehouse management system
eight hundred and forty-eight
one
1 year ago (2024-02-20)

How to select MES system? Main contents of MES production management

Original title: How to select MES system? The main content of MES production management Production and manufacturing activities are the core activities of manufacturing enterprises. As the entity unit of manufacturing activities, planning objectives and the realization of enterprise value, workshop management is the focus of enterprise management. With the rapid development of manufacturing industry, MES is the focus and current hot spot of manufacturing enterprise information automation system
nine hundred and sixty-four
zero
1 year ago (2024-02-20)

The WeChat management system can manage the information content of WeChat more effectively. Let's manage the data of WeChat here

Original title: WeChat management system manages the information content of WeChat more effectively. Many enterprises will assign work to WeChat, because no one wants their personal WeChat to mix work and other related knowledge, but someone will always use the company's loopholes to do something harmful to the company's interests. Don't think such things are rare. I learned about a media financing company in Shenzhen. They have 3
seven hundred and seventy-seven
zero
1 year ago (2024-02-19)

Student electronic file management system, three-dimensional communication space of "home", "school" and "community", and school electronic files

In the era of big data, in the process of recording the growth of students, the school reexamines the management of student files, moves with the times, and promotes the reform of student growth files with new thinking. "Electronic files of primary and secondary school students' growth records" have been gradually introduced into educational management, and show vigorous vitality. Student file management system is an indispensable part of the school, its content for the school
five hundred and seventy-one
zero
1 year ago (2024-02-19)

Ruizhe Information: Select Sitecore? Or... just six steps to choose a content management system, Ruizhe Information Technology Service Co., Ltd

The content management system (CMS) is an important part of the success of website construction. At present, the content management system on the network is relatively complex. It is not easy to find a good content management system that is very suitable for the current digital marketing environment. Before we compare the functionality, operation, scalability, security and other specific performance of the major CMS systems, we need to achieve
three hundred and forty-three
zero

comment

0 people have participated in the review

Scan code to add WeChat

contact us

WeChat: Kuzhuti
Online consultation: