需要在登录用户wordpress的菜单中编辑个人资料链接?
问题描述:
我有一个名为编辑配置文件的页面,我已经安装了配置文件生成器插件,所以用户可以从前端编辑他们的配置文件,如果用户登录,我想显示编辑配置文件和注销链接,是登录。我怎么能做到这一点?我正在使用wp-bootstrap响应主题,我是wordpress开发中的新成员,请帮助我。我是否需要更改header.php文件中的任何内容?需要在登录用户wordpress的菜单中编辑个人资料链接?
<?php
if (is_user_logged_in()) {
// i want to add Edit profile and logout to the menu
} else {
// i want to add login to the menu
} ?>
答
可以使用wp_nav_menu_items
过滤器添加菜单
add_filter('wp_nav_menu_items', 'your_custom_menu_item', 10, 2);
function your_custom_menu_item ($items, $args) {
if (is_user_logged_in()) {
$items .= '<a href="user profile link">Show whatever</a>';
} else {
$items .= '<a href="login link">Show whatever</a>';
}
return $items; /* This will have the menu items */
}
什么WordPress版本您使用的? – Matteo
3.7.1和主题是wp-bootsstrap – Naveenbos