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