How to replace meta title and meta description in wordpress?
<p>Sorry if my question was basic or stupid but please help me to solve this issue. I'm trying to change <code>&lt;title&gt;</code> and <code>&lt;meta name="description" &gt;</code> tags dynamically in wordpress. so this is what I tried in function.php file.</p>

<pre><code>function changeMeta_2(){
    global $wpdb;
    $cur_url = $_SERVER['REQUEST_URI']; 
    $basename = pathinfo($cur_url);
    $ebasename = $basename['filename'];
    if(is_numeric($ebasename)) {
    $url = explode('/', $basename['dirname']);
    $basename = explode('.', $url[count($url)-2]);
    $ebasename = $basename[0];
    }
    $pageName = $ebasename;



    $arraylist_subcat  = array("car","bike","boat","xxxx","yyyy","zzz","mmmm");
    $arraylist_maincat = array("aus","ind","usa","uae");


    $category_id = get_term_by('slug',$pageName, 'category');   
    $category_parentid  = get_term_by('id', $category_id-&gt;parent, 'category');   
    $parent_slug =  $category_parentid-&gt;slug;



   if ( is_page()) {        
        if ( in_array($pageName,$arraylist_maincat) ) {         
                $metaTitle = 'Browse  '.$pageName.' | Some txt title | mysite.com';
                $metaDescription = 'some of custome blablaaaaa text description  '.$pageName.' some of custome blablaaaaa text description ';                               
                echo '&lt;title&gt;'.$metaTitle.'&lt;/title&gt;';
                echo '&lt;meta name="description" content="'.$metaDescription.'"/&gt;';                   
        }
    }
}
add_action( 'wp_head', 'changeMeta_2' );
</code></pre>

<p>In the above code I'm trying to change the title tag and meta description for term id which are matching with array values (in_array condition).</p>

<p>Everything works fine, but problem is instead of override(replace) <code>&lt;title&gt;</code> tag is appending in head. Its not changing it appending. please someone help me to solve this issue.</p>