Home > Backend Development > PHP Tutorial > Some PHP page script skills related to WordPress SEO optimization_php skills

Some PHP page script skills related to WordPress SEO optimization_php skills

WBOY
Release: 2016-05-16 20:03:22
Original
1043 people have browsed it

With the rise of search engines, top-ranked websites attract a large amount of traffic. Whether it is the advertisement on the search page or the results found, the matching degree with the searcher's goal is relatively high (if the search engine is smart enough), so through Visitors coming from search engines are likely to get what they want from the website and remember the website. In other words, search engines will bring a lot of valuable traffic, so take the time to optimize WordPress for search engines. Blogging is also worthwhile. This article will share some WordPress SEO tips for you.

I didn’t spend much time doing search engine optimization before, and the search engine indexing effect was not very good. In February last year, I finally did some SEO for the blog and wrote this article. In the past year and a half, I have done more SEO. Optimization, I haven’t written many blog posts, but the traffic has increased, and the website has returned to PageRank 7, which is quite good. This time I updated the content of this article based on my own WordPress SEO plan.

20151210160816577.png (708×431)

Optimize blog subtitle

Subtitle (slogan), called tagline in WordPress. It is different from the blog title. It may carry some text describing the blog, which can be used after optimization. For example, my subtitle is "mg12's Blog - Just Another WordPress Blog" , the WordPress Blog is set to h1 by me. Because I want to tell the crawler that this is a blog about WordPress.

Distinguish the page title

Do not include the blog name in the page title. WordPress titles generally use bloginfo('name') and wp_title(). The former is the blog name, and the latter is the article title (if the title does not exist, it will not be displayed). The code used to output the title of the classic theme and default theme is as follows.

<title><&#63;php wp_title('&laquo;', true, 'right'); &#63;> <&#63;php bloginfo('name'); &#63;></title>
Copy after login

The output title structure is "Article title » Blog name".

Unless your title is highly relevant to the article content, such a title is obviously not good for SEO. The title is one of the contents that crawlers consider important. If the title contains information that is irrelevant to the article content, how much This page will be affected.

So how should we do it? We can distinguish different types of pages. My implementation code is as follows.

<title><&#63;php
 // 如果是首页和文章列表页面, 显示博客标题
 if(is_front_page() || is_home()) { 
 bloginfo('name');
 
 // 如果是文章详细页面和独立页面, 显示文章标题
 } else if(is_single() || is_page()) {
 wp_title('');
 
 // 如果是类目页面, 显示类目表述
 } else if(is_category()) {
 printf('%1$s 类目的文章存档', single_cat_title('', false));
 
 // 如果是搜索页面, 显示搜索表述
 } else if(is_search()) {
 printf('%1$s 的搜索结果', wp_specialchars($s, 1));
 
 // 如果是标签页面, 显示标签表述
 } else if(is_tag()) {
 printf('%1$s 标签的文章存档', single_tag_title('', false));
 
 // 如果是日期页面, 显示日期范围描述
 } else if(is_date()) {
 $title = '';
 if(is_day()) {
  $title = get_the_time('Y年n月j日');
 } else if(is_year()) {
  $title = get_the_time('Y年');
 } else {
  $title = get_the_time('Y年n月');
 }
 printf('%1$s的文章存档', $title);
 
 // 其他页面显示博客标题
 } else {
 bloginfo('name');
 }
&#63;></title>
Copy after login

Keywords and Description

Keywords provides search engines with the core content of web pages, and Description provides search engines with description information of web pages. The theme I published once included the processing of keywords and description, but due to conflicts with some SEO plug-ins, in newer has been removed from the version. The author believes that many so-called SEO plug-ins in WordPress are not done well and have poor support for Chinese blogs. It may be better to modify them yourself.

The following are my rules for processing keywords, description and page titles. For implementation methods, please refer to the description of page titles in the previous paragraph.

The description of the article detailed page generally takes the first 220 characters of the article. For particularly important pages and articles, you can customize the summary to make the information more accurate. If summary information exists, use the summary, if not, use the previous 220 characters, the implementation code is as follows.

<&#63;php
 if($post->post_excerpt) {
 $description = $post->post_excerpt;
 } else {
 // utf8_trim 方法是为了在截取字符之前对字符串进行转义, 避免出现截取半个汉字的情况
 // 参考文档: http://php-utf8.61924.nl/documentation/functions/utf8_trim.html
 $description = utf8_trim(substr(strip_tags($post->post_content), 0, 220));
 }
&#63;>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template