8

By August 11, 2011

In WordPress Tips


If you’re a theme developer it is handy to keep a record of various pieces of code you can add to your theme’s functions.php file so you can reuse them. In this post I’m going to be listing a number of things you can use to control the WordPress admin area.

1. Enable Hidden Admin Feature displaying ALL Site Settings

This little piece of code does something pretty cool. It will add an additional option to your settings menu with a link to “all settings” which will show you a complete list of all the settings you have within your database related to your wordpress site. The code below will only made this link visible to an admin user and hide it for all other users.

// CUSTOM ADMIN MENU LINK FOR ALL SETTINGS
   function all_settings_link() {
    add_options_page(__('All Settings'), __('All Settings'), 'administrator', 'options.php');
   }
   add_action('admin_menu', 'all_settings_link');

Source

2. Remove Update Notification for all users except Admins

This code will ensures that no users other than admins are notified by wordpress when updates are available.

// REMOVE THE WORDPRESS UPDATE NOTIFICATION FOR ALL USERS EXCEPT SYSADMIN
       global $user_login;
       get_currentuserinfo();
       if (!current_user_can('update_plugins')) { // checks to see if current user can update plugins
        add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
        add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
       }

Source

3. Modify the Login Logo & Image URL Link

This code will allow you to easily modify the WordPress Login page Logo as well as the href link and alt text of this logo.

// CUSTOM ADMIN LOGIN HEADER LOGO
   function my_custom_login_logo() {
echo '';
   }
   add_action('login_head', 'my_custom_login_logo');

// CUSTOM ADMIN LOGIN HEADER LINK & ALT TEXT
   function change_wp_login_url() {
    echo bloginfo('url');  // OR ECHO YOUR OWN URL
   }
   function change_wp_login_title() {
    echo get_option('blogname'); // OR ECHO YOUR OWN ALT TEXT
   }
   add_filter('login_headerurl', 'change_wp_login_url');
   add_filter('login_headertitle', 'change_wp_login_title');

Source

4. Customize the order of the admin menu

This code will allow you to reorganize the order of elements in the admin menu. All that you need to do is click on an existing link in the admin menu and copy everything before the /wp-admin/ URL. The order below represents the order the new admin menu will have.

// CUSTOMIZE ADMIN MENU ORDER
   function custom_menu_order($menu_ord) {
       if (!$menu_ord) return true;
       return array(
        'index.php', // this represents the dashboard link
        'edit.php?post_type=events', // this is a custom post type menu
        'edit.php?post_type=news',
        'edit.php?post_type=articles',
        'edit.php?post_type=faqs',
        'edit.php?post_type=mentors',
        'edit.php?post_type=testimonials',
        'edit.php?post_type=services',
        'edit.php?post_type=page', // this is the default page menu
        'edit.php', // this is the default POST admin menu
    );
   }
   add_filter('custom_menu_order', 'custom_menu_order');
   add_filter('menu_order', 'custom_menu_order');

Source

5. Remove unwanted dashboard items

Remove various items from your dashboard. Especially those annoying “incoming links”

add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');

function my_custom_dashboard_widgets() {
global $wp_meta_boxes;
 //Right Now - Comments, Posts, Pages at a glance
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
//Recent Comments
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
//Incoming Links
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
//Plugins - Popular, New and Recently updated WordPress Plugins
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);

//Wordpress Development Blog Feed
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
//Other WordPress News Feed
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
//Quick Press Form
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
//Recent Drafts List
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
}

Source

6. WordPress Custom Admin Footer

I use this for client sites as a simple point of reference to contact me as the dev.

// customize admin footer text
function custom_admin_footer() {
        echo 'add your custom footer text and html here';
}
add_filter('admin_footer_text', 'custom_admin_footer');

Source

7. Custom Dashboard CSS

You can add any changes to the css between the tags.

/* Change WordPress dashboard CSS */
function custom_admin_styles() {
    echo '<style type="text/css">#wphead{background:#069}</style>';
}
add_action('admin_head', 'custom_admin_styles');

Source

8. Post Word Count

Adds a count of total published words to the bottom of the “Right Now” box on the admin dashboard. Useful if you’re using your blog as an outlet for something like NaNoWriMo or if you just want to keep track of how prolific your blogging skills have become.

function post_word_count() {
    $count = 0;
    $posts = get_posts( array(
        'numberposts' => -1,
        'post_type' => array( 'post', 'page' )
    ));
    foreach( $posts as $post ) {
        $count += str_word_count( strip_tags( get_post_field( 'post_content', $post->ID )));
    }
    $num =  number_format_i18n( $count );
    // This block will add your word count to the stats portion of the Right Now box
    $text = _n( 'Word', 'Words', $num );
    echo "<tr><td class='first b'>{$num}</td><td class='t'>{$text}</td></tr>";
    // This line will add your word count to the bottom of the Right Now box.
    echo '<p>This blog contains a total of <strong>' . $num . '</strong> published words!</p>';
}

// add to Content Stats table
add_action( 'right_now_content_table_end', 'post_word_count');
// add to bottom of Activity Box
add_action('activity_box_end', 'post_word_count');

Source

9. Remove WP 3.1 Admin Bar

WordPress 3.1 comes out with a new function called Admin Bar. This bar is added to your site (both on the dashboard and the site itself) if you’re logged in. Want to remove it? That’s quite easy, just read on.

remove_action('init', 'wp_admin_bar_init');

Source

10. Add custom links to WordPress admin bar

Introduced in WordPress 3.1, the Admin bar is a new feature that many users like. Today, I’m going to show how you can add custom links to WordPress admin bar.

function mytheme_admin_bar_render() {
	global $wp_admin_bar;
	$wp_admin_bar->add_menu( array(
		'parent' => 'new-content', // use 'false' for a root menu, or pass the ID of the parent menu
		'id' => 'new_media', // link ID, defaults to a sanitized title value
		'title' => __('Media'), // link title
		'href' => admin_url( 'media-new.php'), // name of file
		'meta' => false // array of any of the following options: array( 'html' => '', 'class' => '', 'onclick' => '', target => '', title => '' );
	));
}
add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' );

Source

Oliver Dale is the founder of Kooc Media, a startup company based in the UK. Kooc Media builds Online Communities, Web Applications, WordPress Plugins and has been publishing content online for many years.

More Posts By


  • http://www.facebook.com/profile.php?id=100001677963127 Ammar Kasbati

    Well 2,5 and 6 solved my problem… Looking for it for a long period of time… Keep it up…

  • http://wplift.com Oli Dale

    Great news :)

  • A.D.

    Hi Dale,

    You have a a very helpful site. Have a question how can I add the date or anything else on the bottom of the wordpress pages where the name of the site is and where it reads Powered By WordPress? Thanks

    A.D.

  • http://wplift.com Oli Dale

    Hello, have a look in your theme’s footer.php file

  • http://blog.creation-site-france.org/ Julien de Weblog

    Hello for the option :Remove WP 3.1 Admin Bar, there is an option in the profile user in admin, no need to add this code!!

  • http://wplift.com Oli Dale

    Hi,
    Yes I’m aware of that – you may want to disable it for people who sign up to the site etc.

  • http://www.perun.net/2011/09/06/wordpress-newsletter-nr-21/ WordPress-Newsletter Nr. 21 | WordPress & Webwork

    [...] 10 Code-Fragmente für den Admin-Bereich: zehn Code-Beispiele mit denen man den Admin-Bereich von WordPress beeinflussen kann. [...]

  • Anonymous

    I was adding your snippet #2 in my functions.php and get_currentuserinfo() isn’t a registered function.

  • http://newsletter.wp-coder.net/2011/12/the-complete-guide-to-branding-your-wordpress-website/ A Free wordpress newsletter » The Complete Guide to Branding Your WordPress Website

    [...] admin area of your WordPress installation. WpLift has covered this topic very well. Check out ‘10 Codes for your Functions.php to Manage The WordPress Admin‘, or ‘How to change the logo on your WordPress Login Page‘. You may also want to [...]

  • http://www.wp-coder.net/the-complete-guide-to-branding-your-wordpress-website/ wp-coder.net » The Complete Guide to Branding Your WordPress Website

    [...] admin area of your WordPress installation. WpLift has covered this topic very well. Check out ‘10 Codes for your Functions.php to Manage The WordPress Admin‘, or ‘How to change the logo on your WordPress Login Page‘. You may also want to [...]

  • http://www.howtobe.pro/the-complete-guide-to-branding-your-wordpress-website How To Be A ProThe Complete Guide to Branding Your WordPress Website – How To Be A Pro – CSS, Plugins, Web Design, Web Development, Wordpress, Wordpress Plugins, Wordpress Templates, Wordpress Themes

    [...] admin area of your WordPress installation. WpLift has covered this topic very well. Check out ‘10 Codes for your Functions.php to Manage The WordPress Admin‘, or ‘How to change the logo on your WordPress Login Page‘. You may also want to [...]

  • http://www.robsteele.co.uk/ affordable websites

    cool post