WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I have the following custom wp-query working on my site:

function custom_front_page($wp_query){
        $wp_query->set('page_id',''); // empty
        // fix conditional functions
        $wp_query->is_page = false;
        $wp_query->is_front_page = true;
        $wp_query->is_archive = true;
        $wp_query->is_post_type_archive = true;

however, altering the query in this way keeps the page link in my wp_list_pages() nav from receiving the current_page_item class (it no longer thinks it's a page at all).

How can I get around this?

PS I know I can make a separate link and apply the class conditionally, but is there a way to alter the function above, or the call to wp_list_pages()?

share|improve this question
up vote 1 down vote accepted

You can use the following filter:

add_filter('wp_list_pages', 'foo_bar');
function foo_bar($html){
    //Create a regex pattern to identify the LI element with preg_match
    //Create another pattern to identify the class attr and alter it with preg_replace
    return $html;

As I'm not familiar with the exact elements you are working with, I can't write up a regex for you. In theory, following these steps should work for you.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.