The meta tags keywords and description provided by the WordPress theme you download are generally poorly made, or not provided at all, which is not conducive to SEO. This article will guide you how to add separate Description and Keywords to the homepage, categories, pages, and article pages.
Many people are using the All in One SEO plug-in to solve this problem, but many people say that this plug-in is not good. At worst, let's implement it ourselves with code.
The editor's code for setting keywords and description is provided below. Add the following code to the WordPress theme header.php between
, and finally save it as UTF-8 encoding, otherwise Chinese characters will be garbled:<?php $description = ''; $keywords = ''; if (is_home() || is_page()) { // 将以下引号中的内容改成你的主页description $description = "露兜博客描述"; // 将以下引号中的内容改成你的主页keywords $keywords = "WordPress, 博客, 编程,php,ludou"; } elseif (is_single()) { $description1 = get_post_meta($post->ID, "description", true); $description2 = str_replace("\n","",mb_strimwidth(strip_tags($post->post_content), 0, 200, "…", 'utf-8')); // 填写自定义字段description时显示自定义字段的内容,否则使用文章内容前200字作为描述 $description = $description1 ? $description1 : $description2; // 填写自定义字段keywords时显示自定义字段的内容,否则使用文章tags作为关键词 $keywords = get_post_meta($post->ID, "keywords", true); if($keywords == '') { $tags = wp_get_post_tags($post->ID); foreach ($tags as $tag ) { $keywords = $keywords . $tag->name . ", "; } $keywords = rtrim($keywords, ', '); } } elseif (is_category()) { // 分类的description可以到后台 - 文章 -分类目录,修改分类的描述 $description = category_description(); $keywords = single_cat_title('', false); } elseif (is_tag()){ // 标签的description可以到后台 - 文章 - 标签,修改标签的描述 $description = tag_description(); $keywords = single_tag_title('', false); } $description = trim(strip_tags($description)); $keywords = trim(strip_tags($keywords)); ?> <meta name="description" content="<?php echo $description; ?>" /> <meta name="keywords" content="<?php echo $keywords; ?>" />
When writing blog posts in the future, you only need to add two custom columns (under the article editing page, if not, click Show Options# in the upper right corner) ##), the first custom column name is keywords, and the column value contains the keywords of this article. Then add a second custom column, the name of the custom column is description, and the subsequent column value contains the description of this log. After using a custom column once, you only need to select it in the drop-down box to write a log in the future. In this way, each article has your customized keywords and description, and you can completely abandon the All in One SEO plug-in.
The description and keywords of the home page and page are written directly using PHP code. You can change the description of the Pandan Blog above to your own. The description of the category page and tag page (tag) directly takes the description of the category or tag. This can be changed in the WordPress management background as needed, and keywords takes the name of the category or tag. If you want to manually define description and keywords for each category, you can change lines 27-28 of the code to:if (is_category('音乐')) { $description = '这里填音乐分类的描述'; $keywords = '这里填音乐分类的关键字,半角逗号隔开'; } elseif (is_category('电影')) { $description = '这里填电影分类的描述'; $keywords = '这里填电影分类的关键字,半角逗号隔开'; } elseif (is_category('戏剧')) { $description = '这里填戏剧分类的描述'; $keywords = '这里填戏剧分类的关键字,半角逗号隔开'; } // 多个分类,复制9-12行代码,粘贴到13后面行,类似5-12行,改一下分类名称即可 // 使用UTF-8编码另存为,替换原来的文件,否则可能会乱码-- End-- Recommended learning :《
WordPress Tutorial》
The above is the detailed content of WordPress sets independent Description and Keywords. For more information, please follow other related articles on the PHP Chinese website!

Can learn WordPress within three days. 1. Master basic knowledge, such as themes, plug-ins, etc. 2. Understand the core functions, including installation and working principles. 3. Learn basic and advanced usage through examples. 4. Understand debugging techniques and performance optimization suggestions.

WordPress is a Content Management System (CMS). It provides content management, user management, themes and plug-in capabilities to support the creation and management of website content. Its working principle includes database management, template systems and plug-in architecture, suitable for a variety of needs from blogs to corporate websites.

WordPressisgoodforvirtuallyanywebprojectduetoitsversatilityasaCMS.Itexcelsin:1)user-friendliness,allowingeasywebsitesetup;2)flexibilityandcustomizationwithnumerousthemesandplugins;3)SEOoptimization;and4)strongcommunitysupport,thoughusersmustmanageper

Wix is suitable for users who have no programming experience, and WordPress is suitable for users who want more control and expansion capabilities. 1) Wix provides drag-and-drop editors and rich templates, making it easy to quickly build a website. 2) As an open source CMS, WordPress has a huge community and plug-in ecosystem, supporting in-depth customization and expansion.

WordPress itself is free, but it costs extra to use: 1. WordPress.com offers a package ranging from free to paid, with prices ranging from a few dollars per month to dozens of dollars; 2. WordPress.org requires purchasing a domain name (10-20 US dollars per year) and hosting services (5-50 US dollars per month); 3. Most plug-ins and themes are free, and the paid price ranges from tens to hundreds of dollars; by choosing the right hosting service, using plug-ins and themes reasonably, and regularly maintaining and optimizing, the cost of WordPress can be effectively controlled and optimized.

The core version of WordPress is free, but other fees may be incurred during use. 1. Domain names and hosting services require payment. 2. Advanced themes and plug-ins may be charged. 3. Professional services and advanced features may be charged.

WordPress is easy for beginners to get started. 1. After logging into the background, the user interface is intuitive and the simple dashboard provides all the necessary function links. 2. Basic operations include creating and editing content. The WYSIWYG editor simplifies content creation. 3. Beginners can expand website functions through plug-ins and themes, and the learning curve exists but can be mastered through practice.

People choose to use WordPress because of its power and flexibility. 1) WordPress is an open source CMS with strong ease of use and scalability, suitable for various website needs. 2) It has rich themes and plugins, a huge ecosystem and strong community support. 3) The working principle of WordPress is based on themes, plug-ins and core functions, and uses PHP and MySQL to process data, and supports performance optimization.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function