Change/Set Page Title and Meta Tags from Page Called within a Plugin

Attach to wp_head action hoook function that will display meta tag. Inside that function you can:

  • add your own filter that will allow you to change the value,
  • or change tag value depending of your query vars (sign1, sign2, …) or conditional tags.
add_action( 'wp_head', 'se344297_description_metatag_display', 0 );
function se344297_description_metatag_display()
{
    $site_descr = apply_filters( 'description_tag_filter', 'Sample description text.' );
    if ( !empty($site_descr) )
       echo '<meta name="description" content="' . esc_attr($site_descr) . '">';
}

add_filter( 'description_tag_filter', 'se344297_custom_description_metatag' );
function se344297_custom_description_metatag( $descr )
{
    // use conditional tags or check query var
    // here to override meta tag
    //
    $sign1 = get_query_var('sign1', false);

    if ( $sign1 == 'AAA' ) {
        $descr="AAA description text";
    }
    else if ( $sign1 == 'BBB' ) {
        $descr="Description in case of BBB";
    }

    return $descr;
}