How to Edit functions.php File on WordPress Themes

You need to edit functions.php (file) on WordPress themes if you don’t want to use a plugin to add every little functionality. Yes, for some complicated tasks (eg. SEO), it is better to use a dedicated plugin but not for everything.

Table of Contents

There are two ways to do the task: Using a plugin or editing it manually. Here I explained how you can do it manually without a plugin.

Create a Child Theme

The functions.php is a file of your WordPress theme. Before editing the file, create a child theme of your active theme then activate it like any other theme. If you don’t have a child theme and a new version of your active theme comes and you update, all the changes will be erased and you have to do them again each time. If you need help, read the following article: How to Create a WordPress Child Theme Easily

Edit functions.php via Hosting Control Panel

If you have Direct Admin, Cpanel, or any other web hosting panel, login to it via the URL, username, and password your hosting service provider gave you. Next, Open the File Manager item (or something with similar meaning). In the picture below, see top right.

The Path of the File

After opening File Manager, find a way to go to the public_html folder. This is your website’s root folder. If your WordPress is installed on the root folder, go to wp-content > themes > your-child-theme folder. If your WordPress is installed on any sub-folder, open that folder and go to wp-content > themes > your-child-theme folder.

Please Pay Attention

It is strongly recommended that you make a copy of your theme’s functions.php file before editing it. The copied file name can be something like functions-copy.php. Or download the functions.php file to your local computer and ensure it is downloaded correctly. Even if you are an advanced user, copy or download the file before editing. Because your edit may break the site and in this case, your backup file saves your website.

Edit functions.php File

Right-click on the functions.php file, edit and save it. Add your code snippet at the bottom of existing codes. I recommend keeping one empty line between each code snippet and starting each one with a proper comment. Codes and comments should follow the rules of the PHP language.

For Example:

/* Prevent WordPress from Scaling Large Images */
add_filter( 'big_image_size_threshold', '__return_false' );

/* Remove WordPress admin toolbar items */
function shapeSpace_remove_toolbar_menu() {
  global $wp_admin_bar;
  // Replace 'aioseo-main' with new node id
  $wp_admin_bar->remove_menu('aioseo-main');
}
add_action('wp_before_admin_bar_render', 'shapeSpace_remove_toolbar_menu', 999); 

If There Was No File, Create It

If there is no functions.php file on the mentioned path, create it. Add a new file, name it functions.php, and then start editing. The content of this file should start with <?php and then your codes. An example similar to the above but just in this case we created the functions.php file:

<?php

/* Prevent WordPress from Scaling Large Images */
add_filter( 'big_image_size_threshold', '__return_false' );

/* Remove WordPress admin toolbar items */
function shapeSpace_remove_toolbar_menu() {
  global $wp_admin_bar;
  // Replace 'aioseo-main' with new node id
  $wp_admin_bar->remove_menu('aioseo-main');
}
add_action('wp_before_admin_bar_render', 'shapeSpace_remove_toolbar_menu', 999); 

Edit functions.php via FTP

It is the same as editing via the hosting control panel, except that you have to install an FTP client software like WinSCP on your computer. Then you can connect via the account information your hosting provider has given to you. When the FTP connection has been established, go to the file path (like above) and follow the same steps.

Conclusion

I hope this article helps you to modify the WordPress themes functions.php file easily and without breaking your site. For example, you can now include and use Bootstrap in WordPress.

Published on:

Updated on:

Author:

Rate this post and help us improve our content to better serve you.

Help us spread the word! Click the share buttons below to share this post with your followers.

We’d love to hear your thoughts on this topic. Feel free to leave a comment below.

Responses

  1. roku tv Avatar
    roku tv

    I couldn’t resist commenting. Very well written!

    1. Mohammad Ahmadian Avatar
      Mohammad Ahmadian

      I’m so grateful.

Leave a Reply

Your email address will not be published. Required fields are marked *

sixteen − 8 =