tag in header.php Then add the code to set the keywords."/> tag in header.php Then add the code to set the keywords.">
search
HomeCMS TutorialWordPressHow to set keywords in wordpress

How to set keywords in wordpress

Jul 19, 2019 am 10:10 AM

How to set keywords in wordpress

Wordpress officially downloads and installs the program. You can only fill in the website title and subtitle. You can add it through plug-ins, but you are worried that it will affect the overall use of the website. Keywords (keywords) and description ( description) is added with code as follows:

The first step is to enter the WordPress backend, find the "Edit" option under the "Appearance" module, and enter the theme editing options; click "Top (header.php) in the template )" template is as shown in the figure:

How to set keywords in wordpress

How to set keywords in wordpress

The second step is to find

in the header edit box on the left... ..., here is the title of your website, the middle one should be a variable, after all, the title of each page is different.

How to set keywords in wordpress

##The third step is to add code before or after . Adding code after is more in line with our perspective and usage habits. Just put it behind this, the code:

<?php
if (is_home()){
        //这里描述在前*******
 $description = "在此输入描述";
 $keywords = "在此输入关键词";
}
elseif (is_category()){
 $keywords = single_cat_title(&#39;&#39;, false);
 $description = category_description();
}
elseif (is_tag()){
 $keywords = single_tag_title(&#39;&#39;, false);
 $description = tag_description();
}
$keywords = trim(strip_tags($keywords));
$description = trim(strip_tags($description));
?>
<meta name="keywords" content="<?php echo $keywords; ?>" />
<meta name="description" content="<?php echo $description; ?>" />

The fourth step, the first three steps are to set the keyword description of the homepage, if you also want the keywords (keywords) and description (description) of the page and article, the above Replace all the codes and use the following code:


<?php
//如果是首页
if (is_home()){
   $keywords = "你网站首页的关键字,自己修改吧";
   $description = "你网站首页的描述,自己修改吧";}
    //如果是文章页
elseif (is_single()){
    //默认使用文章页添加关键字
   $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, &#39;, &#39;);        
}        //默认使用文章页添加描述
$description = get_post_meta($post->ID, "description", true);
        //如果为空,使用文章前100个字作为描述
if($description == ""){ 
               if($post->post_excerpt){ 
                  $description = $post->post_excerpt;    
     }else{
           $description = mb_strimwidth(strip_tags(apply_filters(&#39;the_content&#39;,$post->post_content)),0,200);
            }        }}
//如果是页面,使用页面添加的关键字和描述
elseif (is_page()){
        $keywords = get_post_meta($post->ID, "keywords", true);
        $description = get_post_meta($post->ID, "description", true);}
//如果是分类页,使用分类名作为关键字,分类描述作为描述
elseif (is_category()){
        $keywords = single_cat_title(&#39;&#39;, false);
        $description = category_description();}
//如果是标签页,使用标签名作为关键字,标签描述作为描述
elseif (is_tag()){
        $keywords = single_tag_title(&#39;&#39;, false);        
        $description = tag_description();}
//去掉两段空格
        $keywords = trim(strip_tags($keywords));
        $description = trim(strip_tags($description));?>
<meta name="keywords" content="<?php echo $keywords; ?>" />
<meta name="description" content="<?php echo $description; ?>" />

Step 5: The following paragraph must be added in front of . Article pages and pages can be added automatically.

<meta name="keywords" content="<?php echo $keywords; ?>" />
<meta name="description" content="<?php echo $description; ?>" />

For more wordpress-related technical articles, please visit the

wordpress tutorial column to learn!

The above is the detailed content of How to set keywords in wordpress. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What types of websites are not a good fit for WordPress?What types of websites are not a good fit for WordPress?May 07, 2025 am 12:10 AM

WordPressisnotidealforhigh-trafficwebsites,customandcomplexapplications,security-sensitiveapplications,real-timedataprocessing,andhighlycustomizeduserinterfaces.Forhigh-trafficsites,useNext.jsorcustomsolutions;forcomplexapplications,optforDjangoorRub

Can you build a blog with WordPress?Can you build a blog with WordPress?May 06, 2025 am 12:03 AM

Yes,youcanbuildablogwithWordPress.1)ChoosebetweenWordPress.comforbeginnersorWordPress.orgformorecontrol.2)Selectathemetopersonalizeyourblog'slook.3)Usepluginstoenhancefunctionality,likeSEOandsocialmediaintegration.4)Customizeyourthemewithsimplecodetw

How secure is WordPress as a CMS platform?How secure is WordPress as a CMS platform?May 05, 2025 am 12:01 AM

WordPresscanbesecureifmanagedproperly.1)KeeptheWordPresscoreupdatedtopatchvulnerabilities.2)Vetandupdatepluginsandthemesfromreputablesources.3)Enforcestrongpasswordsandusetwo-factorauthentication.4)Chooseahostingproviderwithgoodsecuritypractices.5)Ed

What kind of websites can you build with WordPress CMS?What kind of websites can you build with WordPress CMS?May 04, 2025 am 12:06 AM

WordPresscanbuildvarioustypesofwebsites:1)Personalblogs,easytosetupwiththemesandplugins.2)Businesswebsites,usingdrag-and-dropbuilders.3)E-commerceplatforms,withWooCommerceforseamlessintegration.4)Communitysites,usingBuddyPressorbbPress.5)Educationalp

What are the pros and cons of using WordPress as your CMS?What are the pros and cons of using WordPress as your CMS?May 03, 2025 am 12:09 AM

WordPressisapowerfulCMSwithsignificantadvantagesandchallenges.1)It'suser-friendlyandcustomizable,idealforbeginners.2)Itsflexibilitycanleadtositebloatandsecurityissuesifnotmanagedproperly.3)Regularupdatesandperformanceoptimizationsarenecessarytomainta

How does WordPress compare to other popular CMS platforms?How does WordPress compare to other popular CMS platforms?May 02, 2025 am 12:18 AM

WordPressexcelsineaseofuseandadaptability,makingitidealforbeginnersandsmalltomedium-sizedbusinesses.1)EaseofUse:WordPressisuser-friendly.2)Security:Drupalleadswithstrongsecurityfeatures.3)Performance:GhostoffersexcellentperformanceduetoNode.js.4)Scal

Can you use WordPress to build a membership site?Can you use WordPress to build a membership site?May 01, 2025 am 12:08 AM

Yes,youcanuseWordPresstobuildamembershipsite.Here'show:1)UsepluginslikeMemberPress,PaidMemberSubscriptions,orWooCommerceforusermanagement,contentaccesscontrol,andpaymenthandling.2)Ensurecontentprotectionwithupdatedpluginsandadditionalsecuritymeasures

Does WordPress require coding knowledge to use as a CMS?Does WordPress require coding knowledge to use as a CMS?Apr 30, 2025 am 12:03 AM

You don't need programming knowledge to use WordPress, but mastering programming can improve the experience. 1) Use CSS and HTML to adjust the theme style. 2) PHP knowledge can edit topic files and add functions. 3) Custom plug-ins and meta tags can optimize SEO. 4) Pay attention to backup and use of sub-topics to prevent update issues.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software