Useful Tricks for the WordPress Functions File


Share on facebook
Share on google
Share on twitter
Share on linkedin

An Introduction to the WordPress Functions File

he features file behaves kind of a WordPress Plugin, adding elements and performance to a WordPress site. You can use it to call functions, each PHP and built-in WordPress, and to stipulate your personal functions. The functions file is one in every of WordPress’s center files. In other words, it’s one that facilitates the energy of the entire platform, and it’s behind many of the features on your site.

1. Remove Your WordPress Version Number

As you possibly know, depending on the theme you’re using, WordPress tends to show its model range in your site’s footer. It’s a tiny detail that you can do away with without problems with this code:

function wpb_remove_version() {
return '';
add_filter('the_generator', 'wpb_remove_version');

2. Remove “Welcome Panel” from WordPress Dashboard

Your welcome panel is the area of your dashboard that seems as soon as you log into WordPress, and it typically contains a few recommendations and checklists to get you started. With this code snippet, you’ll be in a position to do away with it permanently. You can easily Remove/hide by adding this code in your functions file.

remove_action('welcome_panel', 'wp_welcome_panel');

3. Hide admin bar (during development)

You can hide by adding the below code in your functions file.

show_admin_bar( false );

4. Disable XML-RPC in WordPress

XML-RPC may be a methodology that allows third-party apps to talk alongside your WordPress internet site remotely.
this might cause security problems and may be exploited by hackers.
Simply add this code to your functions file to show off XML-RPC in WordPress:

add_filter('xmlrpc_enabled', '__return_false');

5. Change Background Color Randomly in WordPress

if you want to change background color randomly on your WordPress upon each visit and page reload? Here is how to easily do this, First you would like to feature this code to your theme’s functions file.

function wpb_bg() { 
$rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
$color ='#'.$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].
echo $color;

Next, you need to edit the header.php file in your theme. Find the tag and add replace it with this line:

<body <?php body_class(); ?> style="background-color:<?php wpb_bg();?>">>

Now you can save your changes and visit your website to see Result.

6. You can add Additional Image Sizes in WordPress

WordPress automatically creates several image sizes once you upload a picture. You can also add additional image sizes to use in your theme. Add this code to your theme’s functions file.

add_image_size( 'sidebar-thumb', 120, 120, true ); // Hard Crop Mode
add_image_size( 'homepage-thumb', 220, 180 ); // Soft Crop Mode
add_image_size( 'singlepost-thumb', 590, 9999 ); // Unlimited Height Mode

This code adds three new image sizes with different sizes. using this code you can display image size anywhere in your theme.

<?php the_post_thumbnail( 'homepage-thumb' ); ?>

7. Add New Navigation Menus to Your Theme

WordPress allows us to define navigation menus and then display them. Place this code in your theme’s functions file to define a new menu location in your theme.

function wpb_custom_new_menu() {
register_nav_menu('my-custom-menu',__( 'My Custom Menu' ));
add_action( 'init', 'wpb_custom_new_menu' );

Go to Appearance » Menus and click on ‘My Custom Menu’ and click on save menu.

Custom Menu

Now you need to place this code in your theme where you want to display the menu.

wp_nav_menu( array(
'theme_location' => 'my-custom-menu',
'container_class' => 'custom-menu-class' ) );

Interested in Web Development, Designing & SEO services for your website? Get Free Consultation.