How to Add Meta Descriptions to WordPress Themes Using functions.php

While working on an SEO for WordPress course recently, I was looking for a way to manually add meta descriptions to a theme from the functions.php file.

After playing around a bit, I came up with this solution:

This of course raises the bigger question of why would you want to do this instead of using a plugins like SEO by Yoast or All in One SEO.  I don’t think that you actually would :p I just wanted to demonstrate how to do it.

If you have a more elegant solution, please suggest away!

8 thoughts on “How to Add Meta Descriptions to WordPress Themes Using functions.php

  1. Szabesz

    Hi Zac,

    Thanks for sharing it! I like it 🙂 SEO by Yoast or All in One SEO or the others are a little bit of bloatware I think and the fewer plugins we have the better too. In March the news came out that Yoast WP SEO was open to SQL injection, for example. So that is why 🙂

    Like

    Reply
  2. Joshua Jarvis

    I’m working on a project now where a page is created by a theme but there’s no access to it outside rudimentary basics. This is a great option since even Yoast can’t see it.

    Like

    Reply
  3. Piotr Kula

    Hey, I’ve been searching many hours for such solution. It saved my day because nothing else works with my wordpress theme and I didn’t want to use plugins to solve this problem.
    THANKS!

    Like

    Reply
  4. amitworkdesk

    Hello Zac Gordon what I experienced is Instead of using SEO by yoast plugin. I want to use custom meta tags. I know which one are the best meta tags that google loves. Yoast’s plugin doing less job in this case. They are asking to pay more than one keyword. Even If I will upgrade to premium they will still miss a lot of things that effect our ranking. So What I am doing is I am making custom meta box for post and pages. I am going to use those meta box in wp_head.

    Practical Example:
    If you are going to search web designer in India then check first result open the website then press ctrl+u You will see they are not using any plugin and still on top number with just correct tags.

    Like

    Reply
  5. Ayodele Patrick Ogunlana

    Thanks, Zac you’re the best. You just saved me days of endless searching. I couldn’t use Yoast or WPSEO as they conflicted with other plugins on my site. I found a partially working code from elegantthemes blog to add meta tags to head but the code to display excerpt wasn’t working and the author won’t update the code. Every time I search online, the only thing people recommend is to use Yoast. You’re the only one who provides really working implementation and I’ve added a link to your site in the code so I can come back here again in the future. Thanks again for the help.

    Like

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s