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
@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!
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!!
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;
}
Yes, thank you, i’m really appreciate your contribution. This could be an update for DWQA in the new version. Thank you very much !
Please login or Register to submit your answer