Robin Wang
asked 9 years ago

Hello,

I just installed the plugin to test. The plugin’s function and style are great, but i found that the questions category and tag’s page haven’t category name and tag name in title meta tag, only display site name. I have tried to modify it, but haven’t successed, WP SEO plugin also can’t edit the DWQA’s title tag. My wordpress is V4.2.2. How to get the question category and tag names to related page title?

Many thanks,
Robin

2 Answers
Allen
answered 9 years ago

@robin Wang: hi, you can get this by open your theme file: function.php and add this code bellow:

add_filter('wp_title', 'dw_qa_custom_title', 99 );
function dw_qa_custom_title( $title )
{   
    $tax = get_query_var( 'taxonomy' );
    if ( is_tax('dwqa-question_category') || $tax == 'dwqa-question_category' )
    {
        $category = get_query_var('term');
        $title = 'Question category : '. $category;
    } elseif ( is_tax('dwqa-question_tag') || $tax == 'dwqa-question_tag' ) {
        $tag = get_query_var('term');
        $title = 'Question tag : '. $tag;
    }
    return $title;

}

Hope this help. Glad!

robinfly
replied 9 years ago

Hi, nobita,
Thank you very much! Your code is working, but the title will get the slug only. I modified it as this to get the name of DW’s category and tag:

add_filter(‘wp_title’, ‘dw_qa_custom_title’, 99 );
function dw_qa_custom_title( $title )
{
$term = get_term_by(‘slug’,get_query_var(‘term’),get_query_var(‘taxonomy’));

$tax = get_query_var( 'taxonomy' );
if ( is_tax('dwqa-question_category') || $tax == 'dwqa-question_category' )
{
    $category = $term->name;
    $title = 'Question category : '. $category;
} elseif ( is_tax('dwqa-question_tag') || $tax == 'dwqa-question_tag' ) {
    $tag = $term->name;
    $title = 'Question tag : '. $tag;
}
return $title;

}

It works perfect now. Many thanks!!

Robin Wang
answered 9 years ago

Comment section can’t insert code correctly. So i pasted the final code here again:

add_filter('wp_title', 'dw_qa_custom_title', 99 );
function dw_qa_custom_title( $title )
{   
        $term = get_term_by('slug',get_query_var('term'),get_query_var('taxonomy'));

    $tax = get_query_var( 'taxonomy' );
    if ( is_tax('dwqa-question_category') || $tax == 'dwqa-question_category' )
    {
        $category = $term->name;
        $title = 'Question category : '. $category;
    } elseif ( is_tax('dwqa-question_tag') || $tax == 'dwqa-question_tag' ) {
        $tag = $term->name;
        $title = 'Question tag : '. $tag;
    }
    return $title;

}
nobita
replied 9 years ago

Yes, thank you, i’m really appreciate your contribution. This could be an update for DWQA in the new version. Thank you very much !

Powered by DW Question & Answer Pro