I am currently trying to change the outputted class that wp_list_pages is outputting. However, I don't wish to conduct a global change hence a simple filter is not an option i.e. Only this menu when generated by the shortcode should have a different class.
Currently, I'm producing my menu like this in the header.php:
<nav class="uk-navbar uk-navbar-attached" data-uk-sticky>
<ul class="uk-navbar-nav uk-width-1-1">
<?php do_shortcode('[top_main_menu]');?>
</ul>
</nav>
In functions.php I have the following, noting I've tried two methods and neither work (Obviously I am not doing both at the same time)
/* Call using: [top_main_menu] */
add_shortcode( 'top_main_menu', 'echo_top_main_menu' );
function echo_top_main_menu() {
//Doesn't work
echo str_replace("page_item", "uk-hidden-small", wp_list_pages('echo=false&exclude=134,115,104&sort_column=menu_order&title_li='));
//Doesn't work
echo preg_replace('/li class\=\"/', 'li class="uk-hidden-small ', wp_list_pages('echo=false&exclude=134,115,104&sort_column=menu_order&title_li='));
}
Edit: Trial with filters. Updates class but effects all wp_list_pages instances, not just the one in the short code.
/* Call using: [top_main_menu] */
add_shortcode( 'top_main_menu', 'echo_top_main_menu' );
function echo_top_main_menu() {
add_filter('wp_list_pages', create_function('$t', 'return str_replace("<li class=\"page_item", "<li class=\"uk-hidden-small ", $t);'));
$output = wp_list_pages('echo=false&exclude=134,115,104&sort_column=menu_order&title_li=');
remove_filter('wp_list_pages', create_function('$t', 'return str_replace("<li class=\"page_item", "<li class=\"uk-hidden-small ", $t);'));
echo $output;
}
Currently, no matter what, the following it outputted on the menu:
<li class="page_item page-item-78"><a href="https://www.example.com/some-page/">Some Page</a></li>
However, I require:
<li class="uk-hidden-small page-item-78"><a href="https://www.example.com/some-page/">Some Page</a></li>
I'm aware a Walker is an option but surely the string return from wp_list_pages should be editable via string replace or similar?
ul.uk-hidden-small li { }
instead ofuk-hidden-small
.wp_list_pages
.