Get more control over your WordPress Website’s Dashboard with these effective and easy to add code snippets.

After much research we feel we have been able to provide a very useful and thorough list of WordPress functions.php code snippets as well as a few other great WordPress customization techniques.

The Online Lifesaver will show you the way to a personalized, customized WordPress Dashboard. As well as a more functional theme. Some of these code snippets can also be utilized with adding various plugins to your site, however this at times can cause plugin conflict and theme issues.

So without further ado, Here are your top WordPress Code Snippets fora custom WordPress Website.

Add these code snippets to your functions.php file within your theme’s folder.

1. Permit Shortcodes in your sidebar widgets.
Use this code snippet to allow your sidebar widgets to properly utilize shortcodes provided from your various plugins.

add_filter('widget_text', 'do_shortcode');

2. Remove Meta Boxes from your post and page edit screen.
Use this code snippet to remove unwanted meta box options from your page and post edit screens.

/*Remove meta boxes from default posts screen*/
function remove_default_post_screen_metaboxes() {
    remove_meta_box( 'postcustom','post','normal' ); // Custom Fields Metabox
    remove_meta_box( 'postexcerpt','post','normal' ); // Excerpt Metabox
    remove_meta_box( 'commentstatusdiv','post','normal' ); // Comments Metabox
    remove_meta_box( 'trackbacksdiv','post','normal' ); // Talkback Metabox
    remove_meta_box( 'slugdiv','post','normal' ); // Slug Metabox
    remove_meta_box( 'authordiv','post','normal' ); // Author Metabox
/*Remove meta boxes from default pages screen*/
function remove_default_page_screen_metaboxes() {
    global $post_type;
    remove_meta_box( 'postcustom','page','normal' ); // Custom Fields Metabox
    remove_meta_box( 'postexcerpt','page','normal' ); // Excerpt Metabox
    remove_meta_box( 'commentstatusdiv','page','normal' ); // Comments Metabox
    remove_meta_box( 'commentsdiv','page','normal' ); // Comments
    remove_meta_box( 'trackbacksdiv','page','normal' ); // Talkback Metabox
    remove_meta_box( 'slugdiv','page','normal' ); // Slug Metabox
    remove_meta_box( 'authordiv','page','normal' ); // Author Metabox

3. Add an Excerpt Box To Your Pages
When writing a “Post” to your various Blog categories WordPress allows you to fill out your own hand-crafted summary of your posts content. To add this functionality to your Pages as well simply copy and paste the following code.

/*Add an excerpt box for pages*/

if ( function_exists('add_post_type_support') ){
    add_action('init', 'add_page_excerpts');
    function add_page_excerpts(){
        add_post_type_support( 'page', 'excerpt' );

4. Custom Brand your Dashboards Header & Footer
We all love to see our Brand represented to its fullest. Make sure that even your subscribers can login and edit their contact info while still seeing your Brand within the Dashboard of your site both in the header and the footer. Simply add this code snippet and you will be set.

/*Change Dashboard Header Image*/
add_action('admin_head', 'my_custom_logo');
function my_custom_logo() {
    echo '#header-logo { background-image: url('insert image address here') !important; }';
/*Change Dashboard Footer*/
function remove_footer_admin () {
    echo 'Fueled by WordPress | Customization By: Warford Designs';
add_filter('admin_footer_text', 'remove_footer_admin');

5. Custom Brand Your WordPress Login Screen
With this easy to add code snippet you will be able to add a custom Logo design to replace the standard WordPress Logo.

/*Custom Branded Login Logo*/
function my_custom_login_logo() {
    echo 'h1 a { background-image:url('.get_bloginfo('template_directory').'/images/logo.png) !important;}';
add_action('login_head', 'my_custom_login_logo');
function change_wp_login_url() {
    echo bloginfo('url');
function change_wp_login_title() {
    echo get_option('blogname');
add_filter('login_headerurl', 'change_wp_login_url');
add_filter('login_headertitle', 'change_wp_login_title');

6. Remove the Themes Menu From The WordPress Dashboard
Sometimes we do not want our clients or colleagues playing around with the Theme we just spent so much time tweaking and modifying to be just right. To protect your theme from being changed by an over zealous colleague or client add this code to your functions.php file and watch it disappear before your very eyes.

/*Remove theme menus*/
add_action('admin_init', 'remove_theme_menus');
function remove_theme_menus() {
    global $submenu;

7. Remove Unused Menu Items from your WordPress Dashboard
Like your Theme there are other areas you may want to protect from your clients or colleagues WordPress Dashboard. Add this code to your functions.php file and simply customize the selection to your specific needs.

function remove_menus () {

global $menu;
        $restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins'));
        end ($menu);
        while (prev($menu)){
            $value = explode(' ',$menu[key($menu)][0]);
            if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
add_action('admin_menu', 'remove_menus');

8. How To Remove The WordPress Admin Bar
Since WordPress was updated to Reinhardt Version 3.1 WordPress has provided its logged in users an admin bar displaying over your website. Though some enjoy this added feature for its convenience, some find it annoying and out of place for their needs. As such we thoguht you may be able to make use of this helpful code snippet.

Remove The Admin Bar Completely

function my_function_admin_bar(){
    return false;
add_filter( 'show_admin_bar' , 'my_function_admin_bar');

Allow Administrator to See Admin Bar

function my_function_admin_bar($content) {
    return ( current_user_can("administrator") ) ? $content : false;
add_filter( 'show_admin_bar' , 'my_function_admin_bar');

9. Limit The Maximum File Upload Size
This is great if you have a hosting package that only allows a specified amount of space. The last thing you want is for someone to take up all your space with a few oversized images, or zip files that your clients will not even have the patience to wait for it to load anyways. Copy and paster this code into your functions file, replace the “x” in the statement with the file saze max you have chosen.

add_filter('wp_handle_upload_prefilter', function($file) {
    $size = $file['size'];
    if ($size > 500 * 1024) {
       $file['error'] = '"Files larger than X bytes are prevented from uploads.';
    return $file;

10. Force Visitors To Login Before Viewing Your WordPress Website.
Would you like to create a true members only area, and protect your pages from prying eyes? Well then this code snippet will serve you well. It checks to see if you are logged prior to page loading. If you are not logged in you are redirected to the login.php page. If you are logged in you will be able to access the site.

add_action( 'template_redirect', 'force_login' );
	function force_login()
		$redirect_to = $_SERVER['REQUEST_URI']; // Change this line to change to where logging in redirects the user, i.e. '/', '/wp-admin', etc.
		if ( ! is_user_logged_in() )
			if ( is_feed() )
				$credentials = array();
				$credentials['user_login'] = $_SERVER['PHP_AUTH_USER'];
				$credentials['user_password'] = $_SERVER['PHP_AUTH_PW'];
				$user = wp_signon( $credentials );
				if ( is_wp_error( $user ) )
					header( 'WWW-Authenticate: Basic realm="' . $_SERVER['SERVER_NAME'] . '"' );
					header( 'HTTP/1.0 401 Unauthorized' );
				} // if
			} // if
		  		header( 'Location: /wp-login.php?redirect_to=' . $redirect_to );
			} // else
	  	} // if
	} // force_login

11. Allow your Subscribers to view Private Posts & Pages
Another great way to keep your pages and posts safe from those other then who you choose to see them is to create a private post. However the issue is that a subscriber is not actually capable of viewing Private pages. That was until you found this code snippet to solve your issue.

// Allow subscribers to view private posts and pages
$PrivateRole = get_role('subscriber'); $PrivateRole -> add_cap('read_private_pages');
$PrivateRole -> add_cap('read_private_posts');

12. Permit Contributors To Upload Files
Allow your contributors to upload files to your WordPress website by utilizing this effective code snippet.

if ( current_user_can('contributor') && !current_user_can('upload_files') )
    add_action('admin_init', 'allow_contributor_uploads');

function allow_contributor_uploads() {
    $contributor = get_role('contributor');

13. Add Facebook, Twitter and LinkedIn to your WordPress Profile.
Not all of us use AIM, Yahoo Instant Messenger, or Jabber, secondly three of the largest Social Media Platforms for a Business Representation, that being Facebook, Twitter and LinkedIn are not available options. That is until now, add this code snippet to your functions.php file to swap out those unwanted elements and add in your Facebook Fan Page, Twitter Account & Your LinkedIn Profile instead.

function extra_contact_info($contactmethods) {
    $contactmethods['facebook'] = 'Facebook';
    $contactmethods['twitter'] = 'Twitter';
    $contactmethods['linkedin'] = 'LinkedIn';

    return $contactmethods;
add_filter('user_contactmethods', 'extra_contact_info');

14. Disable Default Dashboard Widgets
Many people ask me how to remove the various default Dashboard widgets from their WordPress CMS, here is a helpful code snippet that will do just that.

// disable default dashboard widgets
function disable_default_dashboard_widgets() {

	// disable default dashboard widgets
	remove_meta_box('dashboard_right_now', 'dashboard', 'core');
	remove_meta_box('dashboard_recent_comments', 'dashboard', 'core');
	remove_meta_box('dashboard_incoming_links', 'dashboard', 'core');
	remove_meta_box('dashboard_plugins', 'dashboard', 'core');

	remove_meta_box('dashboard_quick_press', 'dashboard', 'core');
	remove_meta_box('dashboard_recent_drafts', 'dashboard', 'core');
	remove_meta_box('dashboard_primary', 'dashboard', 'core');
	remove_meta_box('dashboard_secondary', 'dashboard', 'core');

	// disable Simple:Press dashboard widget
	remove_meta_box('sf_announce', 'dashboard', 'normal');
add_action('admin_menu', 'disable_default_dashboard_widgets');

15. Create A Custom Dashboard Widget
With WordPress and a little tweaking of the functions file you are able to display just about anything in your Dashboard which is just what you will see in this easy to add code snippet example we have provided you.

// example custom dashboard widget
function custom_dashboard_widget() {
	echo "

Place your content you want to appear in the Dashboard Widget here.

"; } function add_custom_dashboard_widget() { wp_add_dashboard_widget('custom_dashboard_widget', 'Widget Title Here', 'custom_dashboard_widget'); } add_action('wp_dashboard_setup', 'add_custom_dashboard_widget');