• Resolved joshrodgers

    (@joshrodgers)


    I found a piece of code that adds a class to wp_list_pages menu items:

    function menu_css_class($css_class, $page){
    $css_class[] = "nav_" . $page->post_name;
    return $css_class;
    }
    add_filter("page_css_class", "menu_css_class", 10, 2);

    Is there any way to add the class to the link itself, instead of the li?

    Thanks,
    Josh

Viewing 2 replies - 1 through 2 (of 2 total)
  • I don’t think there is a(n easy) way.

    this is the related section from /wp-includes/post-template.php (line 1058++):

    $css_class = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
    
    		$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_permalink($page->ID) . '">' . $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after . '</a>';

    generally I don’t see any formatting issues the way it is; or any advantages to have the class on the link tag.

    Thread Starter joshrodgers

    (@joshrodgers)

    I was trying to have a div popup when a user clicks on the name of the page, but I decided to go a different route…so I took the page out of the navigation and just added it as a section on the website itself – now it appears on all pages without the need for the popup.

    Thanks,
    Josh

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_list_pages CSS Class’ is closed to new replies.