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?


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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