How To Show Admin Bar Only For Admins
Using the following snippet in your theme’s functions.php file, you will be able to show admin only for admins. Just copy and paste it and you are done.
1 2 3 |
if (!current_user_can('manage_options')) { add_filter('show_admin_bar', '__return_false'); } |
Snippet Source/Credit: Jeff Starr
How To Customize Comment Count Text In WordPress
Using the following snippet, you will be able to customize comment count text in WordPress.
1 2 3 |
<?php echo get_comments_number_text( "No comments, yet", "One Lonely Comment", "% Happy Comments"); ?> |
Snippet Source/Credit: WPSnipp
How To Deregister All In One Event Calendar In WordPress
The following snippet will let you deregister all in one event calendar in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// clean up unwanted JS scripts function my_print_scripts(){ if ( !is_admin() ) { wp_deregister_script('jquery'); wp_deregister_script('ai1ec_requirejs'); } } add_action('wp_print_scripts', 'my_print_scripts'); // clean up unwanted CSS function my_print_css() { if ( !is_admin() ) { wp_deregister_style('ai1ec-general'); wp_deregister_style('ai1ec-event'); wp_deregister_style('ai1ec-calendar'); } } add_action('wp_print_styles', 'my_print_css'); |
Snippet Source/Credit: Ditscheri.com
How To Print Current WordPress Template Being Used
Adding the following snippet to your theme’s functions.php file will let you print current WordPress template being used.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
<?php add_action( 'wp_head', 'admin_print_template_used' ); function admin_print_template_used() { global $template, $current_user, $wp_admin_bar; get_currentuserinfo(); if ( !is_user_logged_in() && $current_user->ID != '1' ) return; if ( is_admin_bar_showing() ) $wp_admin_bar->add_menu( array( 'parent' => false, 'id' => 'template', 'title' => $template, 'href' => '#' )); else print_r( $template ); } // START THE SCRIPT TO PUSH ADMIN BAR TO BOTTOM function fb_move_admin_bar() { echo ' <style type="text/css"> body { padding-bottom: 28px; } body.admin-bar #wphead { padding-top: 0; } body.admin-bar #footer { padding-bottom: 28px; } #wpadminbar { top: auto !important; bottom: 0; } #wpadminbar .quicklinks .menupop ul { bottom: 28px; } </style>'; } // on backend area add_action( 'admin_head', 'fb_move_admin_bar' ); // on frontend area add_action( 'wp_head', 'fb_move_admin_bar' ); ?> |
How To Make A Subdirectory Accessible With WordPress In Root
Adding the following snippet will let you make a subdirectory accessible with WordPress in root.
1 2 3 4 5 6 |
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} ^/(thefoldername).*$ [NC] RewriteRule . - [L] </IfModule> |
Snippet Source/Credit: DreamHost Wiki
How To Disable Sidebars And Widgets On Page Template In WordPress
The following snippet will let you disable sidebars and widgets on page template in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php /* Disables widget areas. */ add_filter( 'sidebars_widgets', 'remove_sidebars' ); function remove_sidebars( $sidebars_widgets ) { global $wp_query; if ( is_singular() ) { $template = get_post_meta( $wp_query->post->ID, "_wp_{$wp_query->post->post_type}_template", true ); // Disables all widgets if ( preg_match("/(-no-widgets.php)$/i", $template ) ) $sidebars_widgets = array( true ); // Disables 'primary' & 'secondary' sidebars widgets if ( preg_match("/(-no-sidebars.php)$/i", $template ) ) $sidebars_widgets['primary'] = false; $sidebars_widgets['secondary'] = false; } return $sidebars_widgets; } ?> |