Я нашел два пути,
Использование фильтров и регулярных выражений
Добавить следующее к вашей теме functions.php
file.
function clean_wp_list_pages($menu) {
// Remove redundant title attributes
$menu = remove_title_attributes($menu);
// Remove protocol and domain name from href values
$menu = make_href_root_relative($menu);
// Give the list items containing the current item or one of its ancestors a class name
$menu = preg_replace('/class="(.*?)current_page(.*?)"/','class="sel"',$menu);
// Remove all other class names
$menu = preg_replace('/ class=(["\'])(?!sel).*?\1/','',$menu);
// Give the current link and the links to its ancestors a class name and wrap their content in a strong element
$menu = preg_replace('/class="sel"><a(.*?)>(.*?)<\/a>/','class="sel"><a$1 class="sel"><strong>$2</strong></a>',$menu);
return $menu;
}
add_filter( 'wp_list_pages', 'clean_wp_list_pages' );
Использование пользовательской функции ходунка
Это то же самое, что и выше. Добавьте это в ваш файл functions.php:
class Clean_Walker extends Walker_Page {
function start_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<ul>\n";
}
function start_el(&$output, $page, $depth, $args, $current_page) {
if ( $depth )
$indent = str_repeat("\t", $depth);
else
$indent = '';
extract($args, EXTR_SKIP);
$class_attr = '';
if ( !empty($current_page) ) {
$_current_page = get_page( $current_page );
if ( (isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors)) || ( $page->ID == $current_page ) || ( $_current_page && $page->ID == $_current_page->post_parent ) ) {
$class_attr = 'sel';
}
} elseif ( (is_single() || is_archive()) && ($page->ID == get_option('page_for_posts')) ) {
$class_attr = 'sel';
}
if ( $class_attr != '' ) {
$class_attr = ' class="' . $class_attr . '"';
$link_before .= '<strong>';
$link_after = '</strong>' . $link_after;
}
$output .= $indent . '<li' . $class_attr . '><a href="' . make_href_root_relative(get_page_link($page->ID)) . '"' . $class_attr . '>' . $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after . '</a>';
if ( !empty($show_date) ) {
if ( 'modified' == $show_date )
$time = $page->post_modified;
else
$time = $page->post_date;
$output .= " " . mysql2date($date_format, $time);
}
}
}
Чтобы использовать это, вам нужно вызвать wp_list_pages с параметром walker.
<?php
$walker = new Clean_Walker();
wp_list_pages( array(
'title_li' => '',
'walker' => $walker,
) );
?>
Источник: здесь