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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With