WordPress SEO with Yoast SEO Plugin

WordPress has a good base for SEO: clean HTML, permalinks, a title tag and automatic sitemaps. A plugin like Yoast SEO adds an easy screen for the title, the description and the focus keyphrase of each page. This chapter shows what is already done by WordPress itself, and what Yoast adds.

What WordPress does without any plugin

Terminal output

$ curl -s -o /dev/null -w "sitemap: %{http_code}\n" http://example.com/wp-sitemap.xml
sitemap: 200
$ curl -s http://example.com/wp-sitemap.xml | grep -o "<loc>[^<]*</loc>"
<loc>http://example.com/wp-sitemap-posts-post-1.xml</loc>
<loc>http://example.com/wp-sitemap-posts-page-1.xml</loc>
<loc>http://example.com/wp-sitemap-taxonomies-category-1.xml</loc>
<loc>http://example.com/wp-sitemap-users-1.xml</loc>
$ curl -s http://example.com/robots.txt
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php

Sitemap: http://example.com/wp-sitemap.xml

Since WordPress 5.5 there is a built in sitemap at /wp-sitemap.xml and WordPress creates a basic robots.txt by itself. The title tag is added when the theme supports title-tag.

Install and activate Yoast SEO

Terminal output

$ wp plugin install wordpress-seo –activate –quiet
$ wp plugin list –name=wordpress-seo –fields=name,status
name status
wordpress-seo active

Set the SEO fields of a post

In the post editor, open the Yoast SEO panel (or the SEO tab in the sidebar). The most important fields are:

FieldWhat to write
Focus keyphraseThe main search phrase for the page, like “wordpress seo”
SEO titleThe title in Google. Keep it about 50 to 60 characters, with the keyphrase near the start
SlugShort URL with the keyphrase
Meta descriptionA summary of 100 to 155 characters which makes people click

Yoast saves these values as post meta. We set them with WP-CLI, which is the same as typing them in the editor panel, and check the HTML of the page:

Terminal output

$ wp post meta update 1 _yoast_wpseo_focuskw "wordpress seo"
Success: Updated custom field '_yoast_wpseo_focuskw'.
$ wp post meta update 1 _yoast_wpseo_title "WordPress SEO Guide for Beginners"
Success: Updated custom field '_yoast_wpseo_title'.
$ wp post meta update 1 _yoast_wpseo_metadesc "A simple WordPress SEO guide: learn titles, meta descriptions, sitemaps and the basic settings which help your site in search."
Success: Updated custom field '_yoast_wpseo_metadesc'.
$ curl -s http://example.com/hello-world/ | grep -E -o '<title>[^<]*</title>|<meta name="description" content="[^"]*"|<link rel="canonical" href="[^"]*"'
<meta name="description" content="A simple WordPress SEO guide: learn titles, meta descriptions, sitemaps and the basic settings which help your site in search."
<link rel="canonical" href="http://example.com/hello-world/"
<title>WordPress SEO Guide for Beginners</title>

Our title, description and canonical link are in the page head now.

Yoast sitemap

Terminal output

$ curl -s -o /dev/null -w "wp-sitemap.xml: %{http_code} %{redirect_url}\n" http://example.com/wp-sitemap.xml
wp-sitemap.xml: 301 http://example.com/sitemap_index.xml
$ curl -s -o /dev/null -w "sitemap_index.xml: %{http_code}\n" http://example.com/sitemap_index.xml
sitemap_index.xml: 200

Yoast replaces the core sitemap with its own at /sitemap_index.xml, and the old address is redirected to it. Send this address to Google Search Console.

Other things for a good WordPress SEO

  • Use Post name permalinks (Permalinks).
  • Make sure Discourage search engines in Settings > Reading is OFF on the live site.
  • Write helpful, original content with clear headings. A plugin cannot do this for you.
  • Add alt text to images and keep the page speed good.
  • Use HTTPS and a mobile friendly theme.
  • Use categories well, and link your related posts to each other.

Do not trust the green light too much

The green traffic light of an SEO plugin only checks simple rules, like the keyphrase in the title. It does not know if your content is really good. Use it as a helper, not as a goal.

Note: Use only one SEO plugin at a time. If you move from one plugin to another, use the import tool of the new plugin, so you keep your titles and descriptions. Next: Create a WordPress Plugin.

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.