AISOP: removing specific meta tags

Question

I am trying to remove specific meta tags generated by All in one SEO pack. Tags are:

<meta property="og:site_name" content="some name">
<meta property="article:author" content="https://someurl.com/">
<meta property="profile:first_name" content="some name">
<meta property="profile:last_name" content="some last_name">
<meta property="profile:username" content="some username">
<meta property="article:published_time" content="2020-04-05T15:42:48+00:00">
<meta property="article:modified_time" content="2020-11-04T20:10:36+00:00">

Also, I am trying to replace <meta property="og:type" content="article"> with <meta property="og:type" content="website">

I can do it the dirty way to remove any tag by adding the code below to functions.php, but I am sure there is a cleaner way. E.g.

add_action('wp_loaded', 'output_buffer_start');//get the buffer before output
function output_buffer_start() { 
    ob_start("output_callback"); 
}

add_action('shutdown', 'output_buffer_end');//end buffering and do the output
function output_buffer_end() { 
    @ob_end_flush(); 
}

function output_callback($buffer) {//do some replacements in the buffer
    $buffer = extractMetaTag($buffer, 'og:site_name');
    $buffer = extractMetaTag($buffer, 'article:author');
    $buffer = extractMetaTag($buffer, 'profile:first_name');
    $buffer = extractMetaTag($buffer, 'profile:last_name');
    $buffer = extractMetaTag($buffer, 'profile:username');
    $buffer = extractMetaTag($buffer, 'article:published_time');
    $buffer = extractMetaTag($buffer, 'article:modified_time');
    $buffer = extractMetaTag($buffer, 'og:type', '<meta property="og:type" content="website">');



    
    $buffer = str_replace($stringsToSearch, $stringsToReplace, $buffer);//removing duplicate ids 
    return $buffer;
}
function extractMetaTag($buffer, $tagProperty, $replacement = ''){
    $tBuffer = explode('<meta property="'.$tagProperty.'"', $buffer, 2);
    $fBuffer = '';
    
    if(count($tBuffer) > 1){
        $fBuffer = $tBuffer[0];
        
        $tBuffer[1] = explode('>', $tBuffer[1], 2);
        $fBuffer.= $replacement.$tBuffer[1][1];
        
        return $fBuffer;
    }
    else{
        return $buffer;
    }
}
0
Timur Gafforov 5 months 2020-12-21T02:10:41-05:00 0 Answers 5 views 0

Leave an answer

Browse
Browse