tag in header.php Then add the code to set the keywords."/> tag in header.php Then add the code to set the keywords.">
Home > Article > CMS Tutorial > 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:
The second step is to find
<?php if (is_home()){ //这里描述在前******* $description = "在此输入描述"; $keywords = "在此输入关键词"; } elseif (is_category()){ $keywords = single_cat_title('', false); $description = category_description(); } elseif (is_tag()){ $keywords = single_tag_title('', 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, ', '); } //默认使用文章页添加描述 $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('the_content',$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('', false); $description = category_description();} //如果是标签页,使用标签名作为关键字,标签描述作为描述 elseif (is_tag()){ $keywords = single_tag_title('', 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!