I need to replace the existing <meta name="description"...>
generated by wp_head() function in header.php with a custom meta description. The information in the page is not a regular wordpress post, is taken from an external DB.
I was able to add my custom meta but the old one is also there
function add_meta_tags()
{
global $data;
if(!is_null($data['metas']['page_meta_description']) )
{
echo '<meta name="description" content="'.$data['metas']['page_meta_description'].'">';
}
}
add_action('wp_head', 'add_meta_tags');
Is there any way to: - delete the default meta description with an action or filter in function.php? or, - replace the value of meta description somehow before is rendered?
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:
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.