Php wp_导航菜单:如果导航菜单先为空,然后添加值

Php wp_导航菜单:如果导航菜单先为空,然后添加值,php,wordpress,Php,Wordpress,我想使用字符串替换替换第一个wp_nav_菜单li值,或者如果第一个值为空,则尝试使用此代码 function mytheme_walk_nav_menu_items($output, $item, $depth, $args) { if ( $args['theme_location'] === 'sub-footer-menu' ) { $current_year = '&copy ' . date("Y").' Mindjet'; $output

我想使用字符串替换替换第一个wp_nav_菜单li值,或者如果第一个值为空,则尝试使用此代码

function mytheme_walk_nav_menu_items($output, $item, $depth, $args) {
    if ( $args['theme_location'] === 'sub-footer-menu' ) {
      $current_year = '&copy ' . date("Y").' Mindjet';
        $output = str_replace( '©2016 Corel', $current_year, $output );
    }
    return $output;
}
  add_filter( 'walker_nav_menu_start_el', 'mytheme_walk_nav_menu_items', 10, 4 );
?> 

您的代码似乎是正确的,但行:

$output = str_replace( '©2016 Corel', $current_year, $output );
只有在$output字符串中找到“©2016 Corel”时,此选项才有效。请打印$output变量以检查里面是否有“©2016 Corel”。如果有一点单一的间距,那么stru-replice也将不起作用