Atomic Smash homepage splash

Create a simple WordPress admin plugin

Words by Anthony HartnellMarch 3, 2017

While there are a number of plugins available for customising the WordPress admin interface, sometimes you don’t want the extra code bloat. This article explains how to develop a simple plugin to override WordPress defaults and make the admin more unique.

Choosing a name

When creating a plugin it’s important to choose a name that is unique to the WordPress plugin directory so that same-name plugins don’t overwrite your code when you update them. WordPress detects plugin updates based on the plugin name and it is recommended in the documentation to check this beforehand.

One of the most common errors in plugin development is overriding an existing function either from WordPress core or within another plugin. This is why it’s essential to prefix everything. A good rule of thumb is to use initials- I’ve chose as_ for Atomic Smash.

Keeping it simple

There are many admin customisation plugins available like WP Admin UI Customize or White Label CMS and they have a lot of useful features but when you need, say just two of the features you might not want to add all that extra code to your site. A plugin also doesn’t need to have an admin page where you specify options- it can be as simple as updating a few variables in the plugin code and never touching the file again.

Step 1: Add a new folder to the plugins directory and create a new file with the same name:

Add the required plugin header requirements

/*
 * Plugin Name: Unique name for the plugin
 * Description: A description of the plugin
 * Version: 1.0
 * Author: Your Name
 * Author URI: Your Website
 */

Update the login logo url

add_filter( 'login_headerurl', 'as_update_login_logo_url' );
function as_update_login_logo_url( $url ) {

    return get_bloginfo( 'url' );

}

Update the login logo image.

This requires a directory called images in your plugin folder. You can either replace the login-logo.png with the same filename or point to a location in the template directory.

 

add_action( 'login_head', 'as_update_login_logo_image' );
function as_update_login_logo_image() {

    $login_logo = plugins_url( 'images/as-login-logo.png', __FILE__ );
    $login_logo_width = 'auto';
    $login_logo_height = '72px';

	echo "<style type='text/css'>
            .login h1 a {
                background-size: cover;
                width: $login_logo_width;
                height: $login_logo_height;
                background-image:url( $login_logo ) !important;
            }
        </style>";

}

Change the text in the admin footer

add_filter( 'admin_footer_text', 'as_change_admin_footer_text' );
function as_change_admin_footer_text() {

    echo sprintf('Simple Admin Customisation written by <a href="%s" target="_blank">%s</a>', 'https://www.atomicsmash.co.uk/', 'Atomic Smash');

}

Remove admin pages

add_action( 'admin_menu', 'as_remove_admin_menu_pages' );
function as_remove_admin_menu_pages() {

    // Set to true / false as appropriate
    $show__dashboard = true;
    $show__posts = true;
    $show__pages = true;
    $show__media = true;
    $show__appearance = true;
    $show__comments = false;
    $show__plugins = true;
    $show__users = true;
    $show__tools = true;
    $show__settings = true;

    if( ! $show__dashboard ) remove_menu_page( 'index.php' );
    if( ! $show__posts ) remove_menu_page( 'edit.php' );
    if( ! $show__pages ) remove_menu_page( 'edit.php?post_type=page' );
    if( ! $show__media ) remove_menu_page( 'upload.php' );
    if( ! $show__appearance ) remove_menu_page( 'themes.php' );
    if( ! $show__comments ) remove_menu_page( 'edit-comments.php' );
    if( ! $show__plugins ) remove_menu_page( 'plugins.php' );
    if( ! $show__users ) remove_menu_page( 'users.php' );
    if( ! $show__tools ) remove_menu_page( 'tools.php' );
    if( ! $show__settings ) remove_menu_page( 'options-general.php' );

}

Finally activate the plugin to see the changes come into effect.

You can download the plugin code here:

Atomic Smash Simple Admin Customisation Plugin (zip format)

Profile picture of Anthony Hartnell

Anthony HartnellDeveloper

Anthony works in the development team and enjoys creating plugins and integrating maps, libraries and other APIs into Wordpress.

Back to top

Keep up to date with Atomic news