0

I am getting the list of Pages and Subpages by wp_list_pages().

I want to change the parent <a> and <ul> child. I found a solution here in this WPSE thread.

But It only changes the <ul>.

How can I add classes/attributes to the both (<a> and <ul>) at once.

0

You can use Walker: extend the Walker_Nav_Menu class in your functions.php

class custom_nav extends Walker_Nav_Menu {
  function start_el (&$output, $item, $depth, $args) {
    $item_output = '<a href="' . $item->url. '" someattr="somevalue">' . $item->title . '</a>';
    $output .= '<li>' . apply_filters ('walker_nav_menu_start_el', $item_output, $item,  $depth, $args);
  }
}

and call it in wp_list_pages

<?php wp_list_pages(array( 'walker' => new custom_nav ())); ?>

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.