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

May 16, 2016 pm 08:03 PM
php wordpress

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
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

WordPress site file access is restricted: Why is my .txt file not accessible through domain name? WordPress site file access is restricted: Why is my .txt file not accessible through domain name? Apr 01, 2025 pm 03:00 PM

Wordpress site file access is restricted: troubleshooting the reason why .txt file cannot be accessed recently. Some users encountered a problem when configuring the mini program business domain name: �...

See all articles