Top Most Wanted WordPress Tweaks

Top Most Wanted WordPress TweaksTop Most Wanted WordPress Tweaks — As you know most people use WordPress to design websites & make a whole new CMS just for the company you want to and its definitely popular around the world. I have seen many sites — Hospital sites, Educational Institution’s site which are proudly powered by WordPress for making their posting of various write-ups easier for the staffs/editors — and I have seen this because some people leave WP Version numbers in the header with a meta tag, Login link at the footer or even make the “wp-admin” accessible for everyone. But for my projects, I never leave these WP related info public for security reasons.

Top Most Wanted WordPress Tweaks

Many of my clients asked me — “How do you apply tweaks to make WordPress user friendly for us?”, That’s actually a nice question and here is me to give you the answers & this is the Top Most Wanted WordPress Tweaks.

IMPORTANT : All the tweaks given below must be placed inside your theme’s function.php file. So Open your theme’s function.php using the Theme Editor inside WordPress or using a file manager & paste the desired codes specified in each tweak, just above “}” (Closing tag) located at the end.

Show a message across the dashboard

Got an alert to make to your users across using the Dashboard & other admin pages? You got something important to tell such as not to update anything via dashboard due to a server migration or an update being applied to the whole site? Well the best way is to put a small script that will make an alert just below the heading of the admin pages.

/* Notice to admin area! */
add_action(‘admin_notices’, ‘tpk_notice_admin’);
function tpk_notice_admin() {
global $current_user ;
$user_id = $current_user->ID;
if ( ! get_user_meta($user_id, ‘ig_tpk_notice’) ) {
echo ‘<div class=”updated”><p>’;
printf(__(‘This site is being shifted to a new server! | <a href=”%1$s”>Hide Notice</a>’), ‘?ignore_notice_tpk=0’);
echo “</p></div>”;
}
}
add_action(‘admin_init’, ‘ignore_notice_tpk’);
function ignore_notice_tpk() {
global $current_user;
$user_id = $current_user->ID;
if ( isset($_GET[‘ignore_notice_tpk’]) && ‘0’ == $_GET[‘ignore_notice_tpk’] ) {
add_user_meta($user_id, ‘ig_tpk_notice’, ‘true’, true);
}
}

Carefully edit “This site is being shifted to a new server!” with your custom text that you want to display to your users. What this does is that, it will display a yellow bar with the text “This site is being shifted to a new server!” with a “Hide Notice” link that will enable the users to hide the message once and for all.

Admin Notice

If you would like to put a red bar instead of the yellow bar, then edit “<div class=”updated”>” to “<div class=”error”>”. It will show like an error message.

Remove unnecessary menus

Its a good idea to disable the menus that you don’t need. The following code will disable the menus which are present the left side of the admin area for all the users.

add_action( ‘admin_menu’, ‘tpk_menulinks_remove’ );
function tpk_menulinks_remove() {
remove_menu_page(‘index.php’); // This is for Dashboard
remove_menu_page(‘edit.php’); // This is for Posts
remove_menu_page(‘upload.php’); // This is for Media
remove_menu_page(‘link-manager.php’); // This is for Links
remove_menu_page(‘edit.php?post_type=page’); // This is for Pages
remove_menu_page(‘edit-comments.php’); // This is for Comments
remove_menu_page(‘themes.php’); // This is for Appearance
remove_menu_page(‘plugins.php’); // This is for Plugins
remove_menu_page(‘users.php’); // This is for Users
remove_menu_page(‘tools.php’); // This is for Tools
remove_menu_page(‘options-general.php’); // This is for Settings
}

Following code will disable the menus present on the left side of the admin area for 1 user.

function tpkmenuremove()
{
global $menu;
global $current_user;
get_currentuserinfo();
if($current_user->user_login == ‘username’)
{
$restricted = array(__(‘Posts’),
__(‘Media’),
__(‘Links’),
__(‘Pages’),
__(‘Comments’),
__(‘Appearance’),
__(‘Plugins’),
__(‘Users’),
__(‘Tools’),
__(‘Settings’)
);
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’, ‘tpkmenuremove’);

where “username” is the user that you want to restrict. You can also put “if($current_user->user_login != ‘admin’)” to apply these restrictions to all the users excluding “admin” — Very handy.

Remove unnecessary meta tags

Like my style, If you really want to remove those annoying meta tags to clean up the header & for security reasons, then place the below codes.

// remove unnecessary meta tags
function metaremovetpk() {
remove_action(‘wp_head’, ‘wp_generator’);
remove_action(‘wp_head’, ‘rsd_link’);
remove_action(‘wp_head’, ‘adjacent_posts_rel_link’);
remove_action(‘wp_head’, ‘wlwmanifest_link’);
remove_action(‘wp_head’, ‘index_rel_link’);
remove_action(‘wp_head’, ‘start_post_rel_link’);
}
add_action(‘init’, ‘metaremovetpk’);

 

Change default FROM email

Mostly, WordPress sent email using FROM address as wordpress@yourdomain.c0m & if you want to change that to any other email ID, then you have to use the following code.

add_filter(‘wp_mail_from’, ‘new_mail_from’);
add_filter(‘wp_mail_from_name’, ‘new_mail_from_name’);

function new_mail_from($old) {
return ‘admin@yourdomain.com’;
}
function new_mail_from_name($old) {
return ‘Your Blog Name’;
}

By doing this can help prevent WordPress emails from going right into your Spam box!

Custom Admin footer

Want to put a link or a message on the footer of the admin pages? Like a contact link for the developer or a reference site or a warm greeting? Well here is it for you.

// 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’);

Disable RSS Feeds

Does your website have only static content? Don’t want the RSS Feeds to be created & published? With this code, you can disable all types of feeds.

function tpk_disable_feed() {
wp_die( __(‘No feed available, Please visit our <a href=”‘. get_bloginfo(‘url’) .'”>homepage</a> to see our site!’) );
}

add_action(‘do_feed’, ‘tpk_disable_feed’, 1);
add_action(‘do_feed_rdf’, ‘tpk_disable_feed’, 1);
add_action(‘do_feed_rss’, ‘tpk_disable_feed’, 1);
add_action(‘do_feed_rss2’, ‘tpk_disable_feed’, 1);
add_action(‘do_feed_atom’, ‘tpk_disable_feed’, 1);

Remove pings to self

Yes – Very annoying, even a website that I created with a lot of pages & posts using WordPress in the late 2011, I was amazed to see a lot of pings from the same site itself. So here it is — the code.

//remove pings
function no_self_ping( &$links ) {
$home = get_option( ‘home’ );
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, $home ) )
unset($links[$l]);
}
add_action( ‘pre_ping’, ‘no_self_ping’ );

Custom Admin logos

Designing for a client? Then its better to change the WordPress login page logo & WordPress admin logo to the client’s company logo. It’s easy, Just change the logo URL using the codes given below.

Login Page logo

function my_custom_login_logo() {
echo ‘<style type=”text/css”>
h1 a { background-image:url(http://path/to/login_page_logo.png) !important; }
</style>’;
}

add_action(‘login_head’, ‘my_custom_login_logo’);

WordPress Admin area logo

function custom_admin_logo() {
echo ‘<style type=”text/css”>
#header-logo { background-image: url(‘.get_bloginfo(http://path/to/admin_page_logo.png) !important; }
</style>’;
}

add_action(‘admin_head’, ‘custom_admin_logo’);




March 9, 2013
/
Previous Post Next Post

Tharun recommends you to read these fantastic articles