How to Add Description Meta tag in WordPress Custom Theme.

Description

It’s help to ranking your post in web search engines. Add description meta tag in your website without any plugin. Just paste given code in your active theme’s functions.php file.

How to add Description Meta Tag

>> Open your active theme’s functions.php file and paste this code.

/**
* description , keyword and canonical url
*/
function add_meta_tags() {
global $post;
if ( is_single() ) {
$meta = strip_tags( $post->post_content );
$meta = strip_shortcodes( $post->post_content );
$meta = str_replace( array("\n", "\r", "\t"), ' ', $meta );
$meta = substr( $meta, 0, 125 );
$meta = wp_strip_all_tags( $meta );
$keywords = get_the_category( $post->ID );
$metakeywords = '';
foreach ( $keywords as $keyword ) {
$metakeywords .= $keyword->cat_name . ", ";
}
echo '
<meta name="description" content="' . $meta . '" />' . "\n";
echo '
<meta name="keywords" content="' . $metakeywords . '" />' . "\n";
}
if( is_home() || is_front_page() ){
$meta_des = "Find all type of information like technical, educational, ayurvedica or more with thekroyaard"; #Edit here
echo '<meta name="description" content="' . $meta_des . '" />';
$meta_key = "Information, Lyrics, Image, Software, Downloadble legal files"; #Edit here
echo '<meta name="keywords" content="' . $meta_key . '" />';
echo '<link rel="canonical" href="http://thekroyaard.com"/>';
}
}
add_action( 'wp_head', 'add_meta_tags' , 2 );

>> Then SAVE it.

Note –

Change or customize highlighted filed according to you. Must be replace canonical with your domain/website url.