最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to Remove the Closing Slash from Meta and Link Tags in WordPress (Astra Theme) - Stack Overflow

programmeradmin1浏览0评论

I am building a WordPress website using the Astra theme, and I noticed that meta and link tags in my site's head section contain closing slashes, like this:

<meta name="description" content="Example description" />
<link rel="canonical" href="/" />

I would like to remove the closing slash so that the tags appear as follows:

<meta name="description" content="Example description">
<link rel="canonical" href=";>

How can I achieve this in WordPress? Is there a filter or function that can modify the output of these tags? Or is there a plugin that allows customization of how meta and link tags are generated?

Any guidance would be appreciated. Thank you!

I tried using the following code in functions.php, but I am not entirely satisfied with this solution:

function fix_self_closing_tags($buffer) {
    return str_replace(' />', '>', $buffer);
}
function start_buffer() {
    ob_start('fix_self_closing_tags');
}
function end_buffer() {
    if (ob_get_length()) ob_end_flush();
}
add_action('template_redirect', 'start_buffer');
add_action('shutdown', 'end_buffer');
发布评论

评论列表(0)

  1. 暂无评论