How to Open WordPress Menu Link in New Window / Tab?

Most of the Developers aren’t aware of the fact that WordPress comes with a bunch of built-in features, hidden inside the Screen Options tab within the dashboard. In this tutorial, we are going to take a look at a simple trick which allows you to open your navigation menu items in a new tab i.e. it adds a target=”_blank” property to the navigation menu items.

Useful Read : Replace Default WordPress jQuery Script with Google Library

To open your menu items in a new tab follow the steps given below:

Step 01: Navigate to Dashboard >> Appearance >> Menus.

How to make a WordPress menu item open in a new window/tab 01

How to make a WordPress menu item open in a new window/tab 01

Step 02: Click on the Screen Options tab on the top right corner or your screen.

How to make a WordPress menu item open in a new window/tab 02

How to make a WordPress menu item open in a new window/tab 02

Step 03: Under Show advanced menu properties section and check Link Target option.

How to make a WordPress menu item open in a new window/tab 03

How to make a WordPress menu item open in a new window/tab 03

Step 04: Now, expand a menu item you wish to open in new tab and check Open link in a new window/tab option.

How to make a WordPress menu item open in a new window/tab 04

How to make a WordPress menu item open in a new window/tab 04

Step 5: Hit Save Menu Button

How to make a WordPress menu item open in a new window/tab 05

How to make a WordPress menu item open in a new window/tab 05

Rename the Uncategorized Category in WordPress

By default, WordPress comes with a built-in category called Uncategorized. It works as the default fallback category. When you publish a post without selecting a category, WordPress automatically assigns that post to Uncategorized  category.

Useful Read: How to Display a Read More link in WordPress Excerpts

I prefer to rename this category to something else, as the name Uncategorized sound unprofessional. To rename this category follow the steps given below.

  1. Login to your WordPress Dasboard.
  2. Navigate to Posts >> Categories.
  3. Move the mouse over Uncategorized.
  4. An edit link will appear. Click the edit link
  5. Change the name and slug.
  6. Hit the Update button
Rename the Uncategorized Category in WordPress

Rename the Uncategorized Category in WordPress

How to Force Dashboard to Display a Single Column Only

This PHP snippet will allow you to force a single column display on your WordPress dashboard.

Useful Read: Exclude Trackbacks and Pingbacks from Comment Count

All you need to do is copy the following code and paste it inside your functions.php file located within your theme directory.

function single_screen_columns( $columns ) {
    $columns['dashboard'] = 1;
    return $columns;
}
add_filter( 'screen_layout_columns', 'single_screen_columns' );
function single_screen_dashboard(){return 1;}
add_filter( 'get_user_option_screen_layout_dashboard', 'single_screen_dashboard' );

 

Restricting Users to View Only Their Own Media Library Items

Here’s a handy code snippet which can be useful to restrict the users to view WordPress media library items they have uploaded. As you can see, we are using manage_options capability to filter users and allow administrators to view all media. To Allow editors to view all media replace manage_options with publish_pages capability.

Useful Read: How To Add URL Column To WordPress Media Library?

add_action('pre_get_posts','restrict_media_library_access');
function restrict_media_library_access( $query ) {
	global $current_user, $pagenow;
	
	if( !is_a( $current_user, 'WP_User') )
		return;

	if( 'admin-ajax.php' != $pagenow || $_REQUEST['action'] != 'query-attachments' )
		return;

	if( !current_user_can('manage_options') )
		$query->set('author', $current_user->ID );

	return;
}

 

How to Change Your Default WordPress Post Category

By default, WordPress comes bundled with a category called Uncategorized. It acts as a fallback category. WordPress assigns this category to a post at the time it is published, if no other category is selected. In other words, it is the default category for WordPress.

If you want to change default category from Uncategorized, to something else, you can do that using Default Post Category option from Dashboard.

To Change the Default Category follow the steps given below,

1. Login to your Dashboard.

2. Navigate to Settings >> Writing

3. Look for Default Post Category option.

4. From the dropdown menu, select a new category and hit the Save Changes button.

How to Change Your Default WordPress Post Category

How to Change Your Default WordPress Post Category

Useful Read:

How To Remove WordPress Version From The Admin Footer

How To Auto Redirect Users After Logout In WordPress

By Default, when you hit the logout button in a WordPress website it redirects you to the login page. However you can easily change this behavior and redirect the user to your desired URL by adding a small amount of code to your functions.php file.

To change the logout URL in WordPress use the following code snippet,

//Redirect after logout
add_action('wp_logout','ccw_redirect_logout_url');
function ccw_redirect_logout_url(){
     wp_redirect(home_url())
     exit;
}

The above code will redirect the user to Home page after logout, but you can also redirect the user to a custom URL by replacing ‘home_url’ with your desired link. For example, following code will redirect the user to http://coffeecupweb.com.

add_action('wp_logout','auto_redirect_external_after_logout');
function auto_redirect_external_after_logout(){
  wp_redirect( 'http://www.coffeecupweb.com' );
  exit();
}

See Also:

Change default search string “?s=” to permalink structure?

 

 

How to Remove Default WordPress Widgets

WordPress comes with number of built-in widgets which allows you to extend the functionality of your WordPress website. But, in most of the cases you may not want all of these default widgets.

How to Remove Default WordPress Widgets

How to Remove Default WordPress Widgets

You can easily disable the unnecessary widgets which are not in use using the following code snippet.

//
function ccw_unregister_default_widgets() {
     unregister_widget('WP_Widget_Pages');			//Page Widget
     unregister_widget('WP_Widget_Calendar');			//Calender Widget
     unregister_widget('WP_Widget_Archives');			//Archive Widget
     unregister_widget('WP_Widget_Links');			//Links Widget
     unregister_widget('WP_Widget_Meta');			//Meta Widget
     unregister_widget('WP_Widget_Search');			//Search Widget
     unregister_widget('WP_Widget_Text');			//Text Widget
     unregister_widget('WP_Widget_Categories');			//Categories Widget
     unregister_widget('WP_Widget_Recent_Posts');		//Recent Posts Widget
     unregister_widget('WP_Widget_Recent_Comments');		//Recent Comments Widget
     unregister_widget('WP_Widget_RSS');			//RSS Widget
     unregister_widget('WP_Widget_Tag_Cloud');			//Tag Cloud Widget
     unregister_widget('WP_Nav_Menu_Widget');			//Menus Widget
 }
 add_action('widgets_init', 'ccw_unregister_default_widgets', 11);

Useful Read: Exclude products from a particular category on the shop page

How to Add a Favicon to Your WordPress Website

What is a Favicon?
Favicon stands for “Favourite Icon”. Favicon is a tiny icon or image that appears next to your website or page title in a web browser.

How to Add a Favicon to Your WordPress Website

How to Add a Favicon to Your WordPress Website

Why do I need one?

  • It Makes your website stand out from you competitors.
  • It helps users to remember your brand.
  • It looks polished and gives a professional edge to your website
  • It allows users to find you website easily in the list of bookmarks

How to add a favicon?
To add a favicon, upload the favicon file to root directory of your website and add the following code to your header.php file

<link rel="icon" href="http://www.example.com/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="http://www.example.com/favicon.ico" type="image/x-icon" />

Change example.com with your website’s URL. And that’s it.

Note: The size of favicon should be 16 X 16 pixal and it should have .ico extension.

Useful Read: Creating a zip file with PHP’s ZipArchive

How to Add post ID to posts and pages admin columns

Here’s a handy PHP code snippet which allows you to add ID column to page and post listing pages on the WordPress dashboard.

Useful Read : How to Add a Featured Image Column to WordPress Dashboard

//Add post ID to posts, pages admin columns
add_filter('manage_posts_columns' , 'custom_set_posts_columns', 5);
add_filter('manage_pages_columns' , 'custom_set_posts_columns', 5);
function custom_set_posts_columns($columns) {
	$columns['post_id'] = __('ID');
	return $columns;
}
add_action( 'manage_posts_custom_column' , 'custom_set_posts_columns_value', 10, 2 );
add_action( 'manage_pages_custom_column' , 'custom_set_posts_columns_value', 5, 2);
function custom_set_posts_columns_value( $column, $post_id ) {
	if ($column == 'post_id'){
		echo $post_id;
	}
}
add_action('admin_head','custom_admin_styling');
function custom_admin_styling() {
	echo '<style type="text/css">';
	echo 'th#post_id{width:50px;}';
	echo '</style>';
}
Add post ID to posts, pages admin columns

Add post ID to posts, pages admin columns