How to Hide Admin Bar for Logged in Users

If you have a WordPress site where end users have to login and you do not want to show the Admin bar to those users then you can disable the Admin bar globally for all users by adding following line of code into your theme’s functions.php file.

//Disable WordPress Admin Bar for all users. */

If you want to disable the Admin Bar for end user but still want to show it for Administrator then use following code:

//Disable WordPress Admin Bar for all users except admins */
function wphelp_remove_adminbar() {
if (!current_user_can('administrator') && !is_admin()) {
add_action('after_setup_theme', 'wphelp_remove_adminbar');

Change WordPress Login Page Logo

Ever wanted to change the default WordPress logo from the wp-login.php page? Well you can do that easily. Copy following snippet and paste it in your theme’s functions.php file and edit the URL of the image.

// login page logo

function wphelp_login_logo() { ?>

<style type="text/css">
	h1 a {
		background-image: url(<?php echo get_template_directory_uri(); ?>/img/text-logo.png) !important;
		width:300px !important;
		height:100px !important;
		background-size: 300px!important;

add_action('login_head', 'wphelp_login_logo');

How to add DNS Prefetch in a WordPress Theme without using Plugin

Go to Google, search for any keyword, hold two seconds and then click the first link, that site will open instantly on your browser without showing you any loading progress.  That is called DNS Preftech.

Google defines it as:

DNS prefetching is an attempt to resolve domain names before a user tries to follow a link. This is done using the computer’s normal DNS resolution mechanism; no connection to Google is used.

So, basically what is happening is that your browser downloads and saves the URL in its buffer and as soon as you click that link it shows you the page from its buffer rather than pulling it from the server. As a developer you cannot know which link your user might click but on certain pages you can anticipate which link a user might click.

For an example, on a blog archive page – a user might click the first news whereas on the single post/page a user might click the home link or the logo to visit the homepage on your site. So, you can add DNS Prefetching for these links based on what you think your user might click next.  You can use the following code snippet and and paste it your theme’s functions.php to enable DNS Prefetching in single post .

if( ! function_exists( 'wphelp_dns_prefetch' ) ) :

	function wphelp_dns_prefetch(){
		if ( is_singular() ) { 
                  echo '<link rel="prefetch" href="' .esc_url( home_url() ) . '">';				
                   echo '<link rel="prerender" href="' .esc_url( home_url() ) . '">';				



add_action('wp_head', 'wphelp_dns_prefetch');

This snippet will enable DNS Prefetching on single post, so when a user is on single post or page or any custom post type and clicks on the link for homepage then the homepage will open without any delay.

Note: DNS Prefetching only works with HTTP2. So if your server does not supports HTTP2 then this will not work.

How to Remove WordPress Dashboard Widgets

Working on a recent project, a client asked me to clean up all the widgets that shown on default WordPress Dashboard as soon as you login. They were not using any of those widgets so wanted to see a clean dashboard upon logging in.

Removing default Dashboard Widgets is easy by adding few lines of codes into your theme’s functions.php file.

Copy the following code and paste it in your functions.php.

function remove_dashboard_meta() {
        remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );
        remove_meta_box( 'dashboard_secondary', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
        remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' );
        remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_activity', 'dashboard', 'normal');//since 3.8
add_action( 'admin_init', 'remove_dashboard_meta' );


How to display all custom fields (name AND value) in a post?

You are working on a custom WordPress theme that uses lots and lots of custom fields and you suddenly want to see what all custom fields are assigned to any post.  You can do by going into the dashboard of the site and editing the specific post but what if you want to show it on the front-end of site on the single post template?

What if you have tons of custom fields and just want to show them all on the single post without specifying specific custom field name/key?

In that case you can use the snippet below inside the post loop to show all the custom fields that are attached to a post:

$custom_fields = get_post_custom();

foreach ( $custom_fields as $field_key => $field_values ) {
	foreach ( $field_values as $key => $value )
		echo $field_key . ' - ' . $value . '<br />';


How to Embed PDFs in a WordPress Page?

Embedding the pdf file in the WordPress page or post is simple and safe. There are various features available in the WordPress in order to embed the pdf file in the page. One of the major thing is in the current version of the WordPress is inbuilt the plugin that need to be activated so that you can easily attach the files like pdf directly inside the page. Similar to the image storage in the page of the WordPress document, you need to follow the same process that is just store the pdf file and then follow the below steps:

  • Open the WordPress dashboard
  • Click on the “Media” Option.
  • And then go with “Add New”.
  • Select the file from the local disc and update it.
  • Copy the path of the pdf file.
  • Paste it in the page in which it is required.

This is one of the normal procedures in order to embed the pdf file in the WordPress . The same process has been implementing the post too. In some cases there may be an option to not visible of the pdf file information in the media library. At that time, you need to customize the option in order to upload the pdf file in it. Use the tag like [pdf]…[/pdf]. There are various parameters are available in the pdf shortag like title, width and height.

Compatibility Of PDF File In WordPress

In general pdf setup used to be horizontal alignment and it supports in most of the browser but in some cases there may be some issue causes because of incompatibility. For example, most of the wordpress user would have experienced such kind of issue that is loading an image in the site would work fine but when you talk about the pdf, maximum number of people would face some problem. Due to some security issue, there may have a chance of viewing the page with blank with grey background. In some other cases, you have only option to click and download the file to view the page instead of viewing it directly.

Secure Access Of PDF Within A Frame

For security reason, most of the professional would suggest that not to use the pdf file directly inside the page so that it go out of range and some of the wording may not be visible or you have to scroll in order to view it. For this reason, you need to create a frame and implement the pdf document within the certain range of the screen and make them to visible with best clarity. Chrome is the browser which fails to update the pdf file rather it must be scaled to 100{37256cf0ee31db86add5b6eba3983cfb5fab0b039501789ef81a53d1a467d5f8}. In internet explorer browser, you need to install the pdf plugin similar to adobe reader software in order to make the pdf document to visible. In mobile browser, one should need to download the file the internal storage or external storage in order to view the pdf document. At maximum time, please avoid using the pdf file rather make use of word documents.