No plug-in WordPress15 practical tips (1)

The power of WordPress is that you can use plug-ins to easily extend the functionality of your site. But sometimes, we need to modify or add the function, just a few lines of code can be done. Today, the theme cat will give you 15 very practical WordPress skills, and do not need any WordPress plugin.
In the WordPress official plugin directory, there are about 40,000 free WordPress plugins that can extend WordPress functionality. In addition, there are many can not count the number of charge plugins. Through these plug-ins, basically can meet the needs of the vast majority of the site.
But sometimes we need some of the features, no need to plug the same can be done. Below, we will give you some very useful WordPress skills, tips, tips, no need to install any WordPress plugin.
This article is longer, divided into two release. This article is the first chapter, the next article will be released within a week:

WordPress Code Tuning: Administrator and Manage Background (Console, Dashboard)
1. Modify the Logo (logo) in the WordPress website login interface
First introduce a technique related to website branding: If you plan to modify your website (or your client’s website) login interface in the WordPress Logo, the following code is just right for you. Use it very simply, just copy the following code into the funcitons.php file on your site’s theme, or in a plugin dedicated to your site:

  1. function my_custom_login_logo() {
  2.     echo ‘<style type="text/css">
  3.         h1 a { background-image:url(‘.get_bloginfo(‘template_directory’).’/images/custom-login-logo.png) !important; }
  4.     </style>’;
  5. }
  6. add_action(‘login_head’, ‘my_custom_login_logo’);

And then do their own Logo, named custom-login-logo.png, upload to the use of the theme directory within the images folder. This code we introduced, but also introduced how to modify the default Logo corresponding to the URL.

2. Modify the Logo of the WordPress management background (dashboard)
Want a WordPress site to stay closer to your business, feel more cordial? Replace WordPress management background (console, dashboard) in the upper left corner of the default WordPress Logo it. Many plugins can do this, but the following code can also directly achieve this function. Similarly, copy the following code into the theme’s funcitons.php file, or in the theme-specific plugin:

  1. function custom_admin_logo() {
  2.   echo ‘<style type="text/css">
  3.           #header-logo { background-image: url(‘.get_bloginfo(‘template_directory’).’/images/admin_logo.png) !important; }
  4.         </style>’;
  5. }
  6. add_action(‘admin_head’, ‘custom_admin_logo’);

Then, you want to use the WP management background in the logo named admin_logo.png, uploaded to the use of the theme directory within the images folder.

3. Close the WordPress login box prompt function
To ensure the security of the WordPress site, it is important that we have written many articles on how to enhance the security of the site. We introduced this technique, but it is a very simple step, but also very useful. The default emptied, when you want to enter the account information log WordPress background, if you enter the information is wrong, WordPress will tell you the error message: the user name does not exist, or password error. This trick is to turn off such tips to enhance the security of the WordPress site.
To disable WordPress login error message, you need to copy the following code into the theme of the funcitons.php file, or within the site-specific plugin:

  1. function no_wordpress_errors(){
  2.   return ‘GET OFF MY LAWN !! RIGHT NOW !!’;
  3. }
  4. add_filter( ‘login_errors’, ‘no_wordpress_errors’ );

In this way, WordPress no longer outputs valid hints that can reduce the likelihood that the site will be compromised.

4. Keep the WordPress login status longer
If you are using WiFi or other wireless network, or use the public computer when the Internet, log on any one site, we must remember to withdraw in time. However, if you at home or company, use their own computer, after a while will be kicked out by WordPress, need to re-login, then it is also very annoying. At this time, you can try this technique to extend the retention time of WordPress login status. Likewise, copy the code into the funcitons.php file or in a site-specific plugin:

  1. add_filter( ‘auth_cookie_expiration’, ‘stay_logged_in_for_1_year’ );
  2. function stay_logged_in_for_1_year( $expire ) {
  3.   return 31556926; // 1 year in seconds
  4. }

By default, if you select the “Remember Me” option when you log in to WordPress, WordPress will remain logged in for 2 weeks. In the above code, we set it to 1 year.

5. Replace “Hello” with “Login as …” in the WordPress toolbar
If you think WordPress at the top of the menu toolbar, the default “Hello” is not suitable for formal occasions, or you want to change a welcome message, please copy the following code to functions.php file, or on the website dedicated plug-in:

  1. function replace_howdy( $wp_admin_bar ) {
  2.     $my_account=$wp_admin_bar->get_node(‘my-account’);
  3.     $newtitle = str_replace( ‘Howdy,’, ‘Logged in as‘, $my_account->title );
  4.     $wp_admin_bar->add_node( array(
  5.         ‘id’ => ‘my-account’,
  6.         ‘title’ => $newtitle,
  7.     ) );
  8. }
  9. add_filter( ‘admin_bar_menu’, ‘replace_howdy’,25 );

In the third line of the above code, the $ newtitle parameter can set the desired greeting. If you want to use Chinese here, please remember to save the file as UTF8 no BOM format.

6. Modify WordPress to manage the background footer text
Brand promotion is to convey information and consistent. So if you create a website for your customers, what you want to do for yourself makes your customers happy and very important to them. Therefore, in addition to changing the login page and management background of the upper left corner of the Logo, you can also manage the background part of the background to add the customer’s slogan (corporate values, vision, etc.) or other interesting text.
Cool! Place the following code in the funcitons.php file, or within the site-specific plugin:

  1. function remove_footer_admin () {
  2.   echo "Your own text";
  3. }
  4. add_filter(‘admin_footer_text’, ‘remove_footer_admin’);

Now, you can add some here to give people a deep impression on the text, or quote some inspirational, connotation of the text, on the echo that line in the double quotation marks on it

 

7. Add short code to the gadget (pendant)
Short code (shorcode, also translated as “short code”, “short code”, etc.) super useful, because they only need a pair of square brackets, you can replace the original very long code snippet. By default, WordPress Widget (pendant, gadget) does not support short code, can only speak short code as ordinary word processing. However, you can simply use the following code in the functions.php file for the theme you are using, or within the site-specific plugin, you can use the short code in the gadget:

  1. define(‘widget_text’, ‘do_shortcode’);

In this way, you can use short code in Widgets (gadgets).