Wordpress replace meta description

大城市里の小女人 提交于 2019-12-01 11:02:39

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.

    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);

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!