国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > CMS > Wordpress > 正文

兩種無插件實現移除WordPress頂部管理工具欄(Admin Bar)方法

2024-09-07 00:51:48
字體:
來源:轉載
供稿:網友

下面我們一起來看一篇關于兩種無插件實現移除WordPress頂部管理工具欄(Admin Bar)方法的使用方法,希望例子可以幫助到大家。

如果沒有經過處理的WordPress網站管理員在登錄之后,如果在前臺頂部肯定會看到管理工具欄(Admin Bar),有些時候甚至影響我們的調試維護速度。因為需要加載很多內置JS甚至有外部的調用,最好的辦法還是直接移除掉比較好。這里老蔣肯定推薦使用無插件實現。

方法之一、直接在用戶面板取消勾選

移除WordPress頂部管理工具欄

在我們管理員用戶中,工具欄勾選去掉保存就可以。

方法之二、修改functions.php

直接在當前主題中的functions.php文件中加上腳本,代碼如下:

add_filter( 'show_admin_bar', '__return_false' );

然后刷新頁面就可以看到頂部管理工具已經去除。

方法之三、增加代碼

將下面的代碼放到你主題的functions.php中就可以完全移出wordpress前端管理工具欄:

  1. if (!function_exists('df_disable_admin_bar')) { function df_disable_admin_bar() { // for the admin page remove_action('admin_footer', 'wp_admin_bar_render', 1000); // for the front-end remove_action('wp_footer', 'wp_admin_bar_render', 1000); // css override for the admin page function remove_admin_bar_style_backend() { echo ''; } add_filter('admin_head','remove_admin_bar_style_backend'); // css override for the frontend function remove_admin_bar_style_frontend() { echo ''; } add_filter('wp_head','remove_admin_bar_style_frontend', 99); } } add_action('init','df_disable_admin_bar');//開源軟件:Vevb.com 

補充:

對所有用戶和訪客禁用頂部工具欄,一行代碼搞定:

remove_action( 'init', '_wp_admin_bar_init' );

僅對管理員用戶顯示頂部工具欄:

  1. if ( !current_user_can( 'manage_options' ) ) {   
  2.     remove_action( 'init''_wp_admin_bar_init' );   

僅在后臺顯示頂部工具欄

或許我們在訪問前臺時可以不用看到它.

  1. if ( is_admin() ) {   
  2.     remove_action( 'init''_wp_admin_bar_init' );   

僅在前臺顯示頂部工具欄

與上條相反的功能,僅僅加了個感嘆號……

  1. if ( !is_admin() ) {   
  2.     remove_action( 'init''_wp_admin_bar_init' );   

移除頂部工具欄28px的間距

某些博客的頂部工具欄前面還有一段空白,可用以下代碼刪除:

  1. function remove_adminbar_margin() {   
  2.     $remove_adminbar_margin = '<style type="text/css">   
  3.         html { margin-top: -28px !important; }   
  4.         * html body { margin-top: -28px !important; }   
  5.     </style>';   
  6.     echo $remove_adminbar_margin;   
  7. }  //開源軟件:Vevb.com 
  8. /* wp-admin area */   
  9. if ( is_admin() ) {   
  10.     remove_action( 'init''_wp_admin_bar_init' );   
  11.     add_action( 'admin_head''remove_adminbar_margin' );   
  12. }   
  13. /* websites */   
  14. if ( !is_admin() ) {   
  15.     remove_action( 'init''_wp_admin_bar_init' );   
  16.     add_action( 'wp_head''remove_adminbar_margin' );   

移除頂部工具欄上的WordPress Logo

  1. function remove_wp_logo() {   
  2.     global $wp_admin_bar;   
  3.     $wp_admin_bar->remove_menu('wp-logo');   
  4. }   
  5. add_action( 'wp_before_admin_bar_render''remove_wp_logo' ); 

移除頂部工具欄上的評論提示

評論提示是什么?就是那個在網站名右邊的泡泡,不需要時可以關掉.

  1. function remove_comment_bubble() {   
  2.     global $wp_admin_bar;   
  3.     $wp_admin_bar->remove_menu('comments');   
  4. }   
  5. add_action( 'wp_before_admin_bar_render''remove_comment_bubble' ); 

移除頂部工具欄“新建”按鈕

  1. function disable_new_content() {   
  2.     global $wp_admin_bar;   
  3.     $wp_admin_bar->remove_menu('new-content');   
  4. }   
  5. add_action( 'wp_before_admin_bar_render''disable_new_content' ); 

移除頂部工具欄“升級”按鈕

在插件或主題有新版本時會自動提示,可直接關閉.

  1. function disable_bar_updates() {   
  2.     global $wp_admin_bar;   
  3.     $wp_admin_bar->remove_menu('updates');   
  4. }   
  5. add_action( 'wp_before_admin_bar_render''disable_bar_updates' ); 

在頂部工具欄添加一個帶鏈接的按鈕:

  1. function custom_adminbar_menu( $meta = TRUE ) {   
  2.     global $wp_admin_bar;   
  3.         if ( !is_user_logged_in() ) { return; }   
  4.         if ( !is_super_admin() || !is_admin_bar_showing() ) { return; }   
  5.     $wp_admin_bar->add_menu( array(   
  6.         'id' => 'custom_menu',   
  7.         'title' => __( 'Menu Name' ),  /* 這里是按鈕的名稱 */ 
  8.         'href' => 'http://google.com/',  /* 注意改里面的鏈接 */ 
  9.         'meta'  => array( target => '_blank' ) )   
  10.     );   
  11. }   
  12. add_action( 'admin_bar_menu''custom_adminbar_menu', 15 );   
  13. /* add_action后面的15是按鈕的位置,具體修改看下 
  14. 10 = 在WP Logo之前 
  15. 15 = 在WP Logo之后 
  16. 25 = 在網站名稱之后 
  17. 100 = 最后 */

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阿勒泰市| 平昌县| 延边| 富源县| 迁安市| 廊坊市| 聂荣县| 曲阜市| 香格里拉县| 灌阳县| 东乡族自治县| 浦城县| 浦北县| 浏阳市| 松潘县| 凤山县| 开原市| 施秉县| 永福县| 双江| 泽库县| 富裕县| 张北县| 枝江市| 吴堡县| 开原市| 监利县| 鄂托克前旗| 泸水县| 克拉玛依市| 灌云县| 安仁县| 老河口市| 兴国县| 响水县| 昌宁县| 吴桥县| 巴林右旗| 都昌县| 宁安市| 洞口县|