Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tips Auto Generate Meta Description Without Plugins In Wordpress
#1
Meta description is an important factor for Search Engine Optimization (SEO). Search engines use it for display snippet in the search results. Via meta description, visitors can see a brief and concise summary of your page’s content. In WordPress, if you use SEO plugins like All-In-One SEO, it already has the built-in feature for auto generation meta description tag. But you can do it yourself without any plugins, and here it is!

The idea of generating meta description is getting the first paragraph of your post and remove all formats, truncate it to a appropriated length so search engines can understand and display it correctly.

To do that, simply paste the following code into your functions.php file of your theme:

Code:
add_action( 'wp_head', 'prefix_meta_desc' );
function prefix_meta_desc() {
    if ( ! is_singular() )
        return;

    $meta = strip_tags( get_post()->post_content );
    $meta = str_replace( array( "\\n", "\\r", "\\t" ), ' ', $meta);
    $meta = substr( $meta, 0, 155 );

    echo "<meta name='description' content='$meta'>";
}

The code above will run only in singular pages (pages, single posts and all single custom post types). It removes all HTML tags from the post content, replaces all special whitespace characters (tabs, new lines) to a single space and truncates it to 155 characters.

Be sure that you added wp_head() in your theme header.php file.

Why should meta description have 155 characters?
According to the study SEO, the appropriate length of meta description is around 155 characters. The search engines don’t recommend an exact number because it depends on which language of your website and the length of the words.

Meta descriptions can be any length, but search engines generally truncate snippets longer than 160 characters. It is best to keep meta descriptions between 150 and 160 characters.

Now you can forget the SEO plugins and makes your theme optimized for SEO. If you find anything interesting about SEO or meta description tag, please let me know in the comments.
[-] The following 1 user says Thank You to lagosmp for this post:
  • Aniexcels
#2
Big Grin
To Purchase Credit Click here , For how to make money on Sologet forum Click here 

HIRE ME FOR WEBSITE DESIGNING US THE PM BUTTON TO SEND ME MESSAGE

There is love in sharing
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  How To Make Your Post Show On Google's First Page lagosmp 0 38 02-10-2019, 09:21 AM
Last Post: lagosmp
  How to Submit Your Website to Google (And Why It Matters) Sureloaded 2 267 12-03-2018, 10:44 AM
Last Post: smartslimhub

Forum Jump:


Users browsing this thread:
1 Guest(s)

Auto Generate Meta Description Without Plugins In Wordpress00