This web page requires JavaScript to be enabled.

Apparently "noscript" tag content shows up in Facebook snippets ;)

How to enable JavaScript?

Local SEO – Page 4 – Elementarray

Local SEO

Programmatically adding Meta Descriptions so we show up nicely in SERPs

There are 2 ways to do this (probably a lot more but I’m showing you two…). The 2 ways that I will show you are mutually exclusive (you can’t have both, or you could, but it would be a pain in the #!). So, here’s my solution, I’m either going to use the WordPress native custom fields, or I’m going to use “ACF” (Advanced Custom Fields). Once you have enabled ACF guess what happens? You no longer have access to the WordPress custom fields interface on posts and pages.

I have code on this website that gets the custom field from a post and injects it into the <meta description=””> tag of the HTML source. This is what Google uses as the snippet underneath SERPs (search engine result pages). Basically this is the code that extracts the individual meta from the WordPress database. Use the codex to understand the parameters…

$key_1_value = get_post_meta( get_the_ID(), 'key_1', true );

I go to the post editor and put in a new custom field, give it a name (meta_description is a good one…) and a value, google will only use the first 156 characters, and legend has it will stop at double quotes…

here is the code I use in my header to get unique meta descriptions for each page or post (you have to configure the custom field on each page or post also)


$allowed_html = wp_kses_allowed_html( 'strip' );
if ( is_page() || is_single() ) {
echo wp_kses( get_post_meta( get_the_ID(), 'meta_description', true ), $allowed_html);
} else {
wp_kses( bloginfo('description'), $allowed_html); ;
}

Without getting into enabling the ACF plugin & configuation of ACF fields, here is an example piece of good that you would put in the header, essentially replacing the one we used in the “get_post_meta()” call:


<meta name="description" content="<?php
// if field does not exist set to false...
$meta_description = get_field('meta_description') ?: false;
echo $meta_description;
?>" />

depending upon your needs, ACF may be a wise choice…

1

Pages: 1 2 3 4 5 6 7 8

Leave a Reply

en_USEnglish