【发布时间】:2014-08-28 06:36:07
【问题描述】:
我有什么:
我在标准 WordPress 导航菜单中有一个登录/注销链接。到目前为止,我已经有条件地将 URL 过滤为必要的登录或注销 URL。
我需要什么:
我还需要有条件地更改导航菜单中链接(菜单项)的文本值。
我的代码:
add_filter( 'nav_menu_link_attributes', 'menu_override_b', 10, 3 );
function menu_override_b( $atts, $item, $args ) {
if ( is_user_logged_in() ) {
$url = wp_logout_url();
$newlink = str_replace("http://--loginout--", $url, $atts[href]);
$atts[href] = $newlink;
//None of the following work...
/*
$title ="Logout";
$atts[title] = $title;
$atts[post_excerpt] = $title;
$atts[description] = $title;
$atts[attr_title] = $title;
$atts[post_title] = $title;
$atts[post_content] = $title;
*/
}
else{
$url = "/somewhere/else";
$newlink = str_replace("http://--loginout--", $url, $atts[href]);
$atts[href] = $newlink;
//None of the following work...
/*
$title ="Login";
$atts[title] = $title;
$atts[post_excerpt] = $title;
$atts[description] = $title;
$atts[attr_title] = $title;
$atts[post_title] = $title;
$atts[post_content] = $title;
*/
}
return $atts;
}
【问题讨论】:
标签: php wordpress attributes navigation