Is Base Page?

Solved6.57K viewsGeneral
0

I’m wanting to do some conditional work based on if AnsPress is on the main base page (show a banner instead of h1 title).

What’s the best way to detect if base page? I had thought about using page title, but it is ANSPRESS_TITLE for all pages and only altered within the_title().

Thanks,

0

Use this:

// To detect if AnsPress
if( is_anspress() ){
    // This is AnsPress.
}

// To detect if main page
if(get_query_var( 'ap_page' ) == '' || get_query_var( 'ap_page' ) == 'base'){
   // This is main base page.
}

Appreciate the quick reply.

This will let me know if it is on *any* of the AnsPress pages, I’m looking specifically for a way to identify the main base page, not any of the other pages (Ask, Question, Answer, Profile, etc)

Updated my answer.

Rahul, sorry this took me so long to get back to you on. I updated to latest version and get_query_var( ‘ap_page’ ) appears to be blank, on the base page and on the question page, so much like the original answer anything within the IF block is executed on all anspress pages.

Unfortunately that doesn’t appear to distinguish between the question list page and the other anspress pages.

Still struggling to figure this.

Thank for your help Rahul, finally got this using a combination of answers:

if( is_anspress() && !get_question_id() && (get_query_var( ‘ap_page’ ) == ” || get_query_var( ‘ap_page’ ) == ‘base’))
{
// Anspress question list page
}
else
{
//Any other Anspress page or non-Anspress page
}

0

For question page you need this condition:

if (get_question_id()){
    //Your codes.
}