How to send HTML emails from WordPress Using wp_mail function?

WordPress comes with a built-in mail function which allows you to easily send emails from your website. This function is called wp_mail() function. However, all mails sent using the wp_mail() function are of  ‘plain/text’ content type which does not allow HTML in the email. If you need to send a HTML formatted email, you have to change the email’s content type to ‘text/html’. To do this we are going to use wp_mail_content_type filter.

To change the content type to HTML paste the following code in your theme’s functions.php file.

//Send HTML emails in WordPress Using wp_mail function
add_filter( 'wp_mail_content_type', 'set_content_type' );
function set_content_type( $content_type ){
	return 'text/html';

Useful Read: Redirect All 404 Errors In WordPress To Home Page

How to show empty categories in WordPress category widget

By default, WordPress does not display empty categories in default category widget. But, you can easily fix this issue by adding the following code snippet to your functions.php file located inside your theme directory. The following code will force the WordPress category widget to display empty categories.

Quick Tip : Hide specific categories from WordPress category widget

//Show empty categories in category widget
function show_empty_categories($cat_args){
	$cat_args['hide_empty'] = 0;
	return $cat_args;


Force categories widget to display empty categories

Force categories widget to display empty categories

How to Add a Login/Logout Link to WordPress Menu

If you allow users to register on your WordPress website/blog, then its really important to add a login/logout link to your website.

In this post, I will show you how to add a login / logout link to the your WordPress navigation menu. This code snippet automatically detects whether the user is logged in or not and display the login or logout link accordingly.

//Add Login/Logout Links To WordPress Navigation Menu
add_filter( 'wp_nav_menu_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link( $items, $args )
    if($args->theme_location == 'primary')
            $items .= '<li><a href="'. wp_logout_url() .'">Logout</a></li>';
        } else {
            $items .= '<li><a href="'. wp_login_url() .'">Login</a></li>';

    return $items;

Note: Change primary to your own theme location.

Useful Read: Applying Categories and Tags to WordPress Media Attachments

How to enable Shortcodes in WordPress text widget

Here’s another useful code snippet I found on WordPress support forums. Its a quick trick which allow you to use Shortcodes in WordPress text widgets.
To enable shortcodes in text widget, add following code into your functions.php file

//Enable Shortcodes in WordPress text widget
add_filter('widget_text', 'do_shortcode');

Now, you can use shortcodes in widgets as you do in post editor.

Useful Read: Exclude or hide categories from category widget in WordPress sidebar

Remove WordPress logo from admin bar

In this tutorial I will show you how to remove WordPress logo from admin bar. To do this we are using global $wp_admin_bar.


To remove logo from admin bar simply copy the following code and paste it inside your functions.php file.

//Remove admin bar logo (
add_action('wp_before_admin_bar_render', 'ccw_remove_admin_bar_logo', 0);
function ccw_remove_admin_bar_logo() {
        global $wp_admin_bar;