• Carl Wuensche

    (@stuffradio)


    I’m trying to strip the
    <li class="page_item page-item-29"> from my sub nav items. I don’t want to have a class item there. What is the regex to do something like this and can you write a function for it for the functions.php file?

    Thanks if anyone helps!

Viewing 3 replies - 1 through 3 (of 3 total)
  • I can’t really see any reason for even doing this other than to just play around with something. Regex isn’t really my area, but something like this might work:

    add_filter( 'wp_list_pages', 'strip_class_from_pages' );
    
    function strip_class_from_pages( $menu ) {
    	return preg_replace( '/<li(.*?)class="(.*?)"/', '<li', $menu );
    }

    There’s probably a better way to do it though.

    Thread Starter Carl Wuensche

    (@stuffradio)

    Thanks for the reply, will try it out. The reason for doing this is because the css the theme uses does not have any li class there, and it just ruins the menu.

    I also need someway to have pages with children to have a different class, how can I use filters to have that show up when there are children?

    Thread Starter Carl Wuensche

    (@stuffradio)

    Scratch the last post I made,

    greenshady thank you for the regex.. it worked! The only thing left I need to complete the theme is to have an extra item added to menus that have sub-pages.

    My menu is like this:

    Item 1 – Item 2 – Item 3 – Item 4 – Item 5
    – Sub 1 – Sub 1
    – Sub 2 – Sub 2

    I want to add an extra sub item in the spots that have sub items, in this case for items 2 and 3.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Regex for wp_list_pages’ is closed to new replies.