【程式碼】 給 bbPress 論壇增加個人資料選單按鈕連結

標籤: 

正在檢視 4 個帖子:1-4 (共 4 個帖子)
  • 作者
    帖子
  • 詩語
    管理員
    • 文章數量: 5,925
    @feibisi
    樓主

    也是因為有點煩,bbPress 功能太簡單了,想要呼叫資料頁面的幾個連結都沒辦法,只能是透過程式碼實現,效果:

    screenshot-2016-12-05-02-12-27

    使用方法,新增到主題的 function.php 檔案中

    * Filter wp_nav_menu() to add profile link
    */
    function prefix_bbp_profile_link_nav_menu($menu) {
    
        if ( !is_user_logged_in() )
            return $menu;
        else
            $current_user 				= 	wp_get_current_user();
            $user					=	$current_user->ID;
            $bbp_profile_url			=       bbp_get_user_profile_url( $user);
            $bbp_profile_menu_link	  	        = 	'<li>
    			        				<a href=" '. esc_url( $bbp_profile_url ) .' "> '. __('👤 我的賬戶', 'text-domain' ) .' </a>
    							</li>';
            $menu         	= 	$menu . $bbp_profile_menu_link;
    
            return $menu;
    
    }
    add_filter( 'wp_nav_menu_items', 'prefix_bbp_profile_link_nav_menu' );
    詩語
    管理員
    • 文章數量: 5,925
    @feibisi
    樓主

    在未登入的情況下不會顯示

    xingjia10086
    • 文章數量: 8
    @xingjia10086

    報錯了…

     

    詩語
    管理員
    • 文章數量: 5,925
    @feibisi
    樓主

    估計你新增的位置不對,所以才會報錯。

正在檢視 4 個帖子:1-4 (共 4 個帖子)
  • 哎呀,回覆話題必需登入。

話題資訊

  • 當前位於:bbPress
  • 3 條回覆
  • 2 個參與人
  • 最後回覆:<a href="https://bbs.weixiaoduo.com/users/feibisi/" title=" 檢視詩語的個人資料" class="bbp-author-link"><span class="bbp-author-name"> 詩語</span></a>
  • 上次活動:<a href="https://bbs.weixiaoduo.com/topic/21221/#post-22610" title=" 回覆至:【程式碼】 給 bbPress 論壇增加個人資料選單按鈕連結">7 年、 6 月前</a>