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

Video Face Swap

Video Face Swap

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

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)

How to adjust the wordpress article list How to adjust the wordpress article list Apr 20, 2025 am 10:48 AM

There are four ways to adjust the WordPress article list: use theme options, use plugins (such as Post Types Order, WP Post List, Boxy Stuff), use code (add settings in the functions.php file), or modify the WordPress database directly.

What are the plugins for wordpress blocking ip What are the plugins for wordpress blocking ip Apr 20, 2025 am 08:27 AM

WordPress IP blocking plugin selection is crucial. The following types can be considered: based on .htaccess: efficient, but complex operation; database operation: flexible, but low efficiency; firewall: high security performance, but complex configuration; self-written: highest control, but requires more technical level.

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

How to write a header of a wordpress How to write a header of a wordpress Apr 20, 2025 pm 12:09 PM

The steps to create a custom header in WordPress are as follows: Edit the theme file "header.php". Add your website name and description. Create a navigation menu. Add a search bar. Save changes and view your custom header.

How to cancel the editing date of wordpress How to cancel the editing date of wordpress Apr 20, 2025 am 10:54 AM

WordPress editing dates can be canceled in three ways: 1. Install the Enable Post Date Disable plug-in; 2. Add code in the functions.php file; 3. Manually edit the post_modified column in the wp_posts table.

How to change the head image of the wordpress theme How to change the head image of the wordpress theme Apr 20, 2025 am 10:00 AM

A step-by-step guide to replacing a header image of WordPress: Log in to the WordPress dashboard and navigate to Appearance &gt;Theme. Select the topic you want to edit and click Customize. Open the Theme Options panel and look for the Site Header or Header Image options. Click the Select Image button and upload a new head image. Crop the image and click Save and Crop. Click the Save and Publish button to update the changes.

How to build a website for wordpress host How to build a website for wordpress host Apr 20, 2025 am 11:12 AM

To build a website using WordPress hosting, you need to: select a reliable hosting provider. Buy a domain name. Set up a WordPress hosting account. Select a topic. Add pages and articles. Install the plug-in. Customize your website. Publish your website.

WordPress website account login WordPress website account login Apr 20, 2025 am 09:06 AM

To log in to a WordPress website account: Visit the login page: Enter the website URL plus "/wp-login.php". Enter your username and password. Click "Login". Verification Two-step Verification (optional). After successfully logging in, you will see the website dashboard.

See all articles