I need to replace the existing generated by wp_head() function in header.php with a custom meta description. The informatio
The Description Meta tag is generally handled by the template header (header.php) or by a Plugin that is adding the description to the site (Such as SEO Title Tag). Since you are getting a duplicate description, you should check for plugins that are outputting a description tag.
For other annoying meta tags and other things put in the header, you can use the remove_action() function in the functions.php file of your template to do this and can look at the documentation here: https://codex.wordpress.org/Function_Reference/remove_action
I do something similar for a WP site I run and needed to remove every single meta tag that goes into the head and here is the code that I have at the bottom of my functions.php file to do it:
// Remove Meta Tags that are Unneeded
remove_action('wp_head','feed_links_extra', 3);
remove_action('wp_head','rsd_link');
remove_action('wp_head','feed_links', 2);
remove_action('wp_head','wlwmanifest_link');
remove_action('wp_head','index_rel_link');
remove_action('wp_head','parent_post_rel_link', 10, 0);
remove_action('wp_head','start_post_rel_link', 10, 0);
remove_action('wp_head','adjacent_posts_rel_link', 10, 0);
remove_action('wp_head','noindex');
remove_action('wp_head','wp_generator');
remove_action('wp_head','rel_canonical');
remove_action('wp_head', 'wp_shortlink_wp_head');
Obviously, only use the ones you need! I had trouble finding a list of all the functions for the meta-tags so I wanted to include all of the ones I used.
Install Yoast plugin, you will be able to generate meta tags by manually putting it as you want to show on search engine result page.
function remove_meta_descriptions($html) {
$pattern = '/<meta name(.*)=(.*)"description"(.*)>/i';
$html = preg_replace($pattern, '', $html);
return $html;
}
function clean_meta_descriptions($html) {
ob_start('remove_meta_descriptions');
}
add_action('get_header', 'clean_meta_descriptions', 100);
add_action('wp_footer', function(){ ob_end_flush(); }, 100);