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

In relation to question posted here, is it possible to have an output to have something like this instead? where class="parent" is applied to the hyperlink?

    <li><a href="#">Page 1</a></li>
    <li><a class="parent" href="#">Page with Subpages</a>
        <ul class="children">
            <li><a class="parent" href="#">Page with another subpage</a>
                <ul class="children">
                    <li><a href="#">subsubpage</a></li>
    <li><a href="#">Page 3</a></li>
    <li><a href="#">Page 4</a></li>

the function below of TheDeadMedic works well for lists:

function add_parent_class( $css_class, $page, $depth, $args )
    if ( ! empty( $args['has_children'] ) )
        $css_class[] = 'parent';
    return $css_class;
add_filter( 'page_css_class', 'add_parent_class', 10, 4 );

is it possible to use a similar function to target hyperlinks instead of the lists?

share|improve this question

According to this thread, you can add a custom Walker class to your wp_list_pages() call. It looks like that's the way to go, since wp_list_pages() prints or returns a string.

If you set $args['echo'] to false, you can do some string manipulation before you echo() it, but it seems to me that the Walker solution is probably the way to go.

Unfortunately the Walker documentation looks a little thin.

share|improve this answer
thanks, pat. it sure is hard with very little documentation /reference around. i will give the walker approach a try. – Pabile Mar 13 '13 at 7:38
Here's a Walker documentation page with a bit more content: codex.wordpress.org/Function_Reference/Walker_Class . Good luck! – Pat J Mar 13 '13 at 13:18

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.