WordPress SEO Without A Plugin

This method is no longer preferred, it would be best to download a plugin like Advanced Custom Fields and store data through there and just retrieve it.



Naturally, WordPress is a pretty amazing tool by itself. Out of the box, you can literally have website up with content in minutes. Web hosts nowadays have one-click solutions where you can launch a WordPress website in under 5 minutes. While WordPress is mostly optimized for search engines, there are things that can be done to improve SEO, especially without installing a plugin.

I am an advocate for installing the minimum amount of plugins. While it is negotiable whether plugins slow down your website or use resources, there is something about being able to use code without a plugin. For some tasks you want done on your website, a plugin is almost essential, but for many different operations, PHP code can easily do the trick. So for my SEO, I decided to go plugin-free.

SEO Yoast is by far the most popular SEO plugin for WordPress used by millions of people and up until recently (August 29, 2017), I was a loyal fan. I used SEO Yoast for everything and it is definitely a powerful tool. There is nothing wrong with SEO Yoast and I highly recommend using it if your website is not having issues or you prefer to have things easy. I definitely prefer it and had I not run into issues, I would probably still be using it. Unfortunately, SEO Yoast was incompatible with a few things changes I made to the website, messing up to the point where I could no longer see its box, even updating to the latest version, and reverting to older versions. Having used SEO Yoast for the 5+ years, SEO Yoast stored all of its data in a meta tag which can be found in the wp_postmeta table under _yoast_wpseo_metadesc).

Before we start, ensure that any plugin that messes with your meta data is disabled. In this case, disable SEO Yoast.

WordPress comes with a less-commonly used meta field called post_excerpt, which can be displayed by clicking on Screen Options and making sure the Post Excerpt checkbox is checked. This Post Excerpt area is used for display on the main page of the blog when showing posts. For Post Excerpt, I decided to use it as a Meta Description as well, which is usually the first sentence of any article.

The first thing I had to do was transfer all the SEO Yoast Meta Data under the wp_postmeta table to the wp_posts table which contains the post_excerpt field. In order to do this, I had to find out match both tables and their fields. You will need access to your database and the SQL command area.

Here is the code I used:

Set your own Prefix

UPDATE wp_posts INNER JOIN wp_postmeta set wp_posts.post_excerpt = wp_postmeta.meta_value
WHERE wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = '_yoast_wpseo_metadesc';
This will update all of the post_excerpt fields in wp_posts table from the wp_postmeta table for which the IDs match AND the meta key is equal to _yoast_wpseo_metadesc.

Once this is done, you will need to go into the Appearance section in WordPress and navigate to header.php. You can plop this code before the closing head tag or right under the title tag.

PHP tags have been removed because they do not work on MyPost
Add a < in front of meta to activate the code
if(is_home()) {
echo 'meta name="description" content="This is the home page of my website.">';
} else {
echo 'meta name="description" content=".get_the_excerpt($post->ID).">';
}
On the home page will be "This is the home page..." and every page that is not the home page, it will add the excerpt to your meta description, doing what SEO Yoast would have done. This method allows you to disable yet another plugin for hopefully a faster running website.

If you were relying on SEO Yoast for your XML sitemap, you will still need to install another plugin or set one up manually.

I hope this tutorial helped you.