Wednesday, May 18, 2022

Edit function.php file in WordPress – Best 4 ways

WordPress is an excellent CMS, and you can create any website or blog with this CMS. Your front end depends on the theme which you selected for your website or blog. You can find your niche-related themes and use them to get the related function and give the perfect front-end look to your users.

But, it is challenging to find the perfect theme. Maybe you get the ideal WordPress theme for your website, but when you need to add some functionally or modify the functions of your WordPress theme, you have to edit the function.php (function file).

function.php file location in WordPress: [WordPress Root] > Wp-content > Themes > [Your Current Theme] > function.php

What is Function.php?

WordPress offers a Function.php file for the functions. In other words, all the functions of any WordPress theme are available in this file. In addition, you can customize the theme functionality by editing or adding custom code to the function file.

For example, You want to customize the woo-commerce functionality to allow guest checkout on selected products. Then you can do this by adding the custom code to the function file.

It doesn’t matter which theme you are using, and you can edit this file in 4 different ways.

1: Edit function.php file by using FTP client

  • Start your favorite FTP client
  • Connect to the server remotely
  • [WP-Root]>WP-content>themes>[Your Current Theme]>function.php
  • Download the function.php file
  • Edit in your favorite editor
  • Upload edited file and replace with older file

2: Access function.php file from cPanel

To access your function.php file, you have to follow the same path as shown in FTP. These are the steps below to access the function.php from cPanel.

  • Open cPanel and find File Manager.
  • Open File Manager and go to public_html
  • Find wp-content in your WordPress root location ( If you are hosting multiple websites, then you can see the different folders for each website, open your website folder to access the root location )
  • Wp-content >Themes
  • Open your current theme folder.
  • Edit/download function.php file
  • Save after editing the file /replace the older file with the edited file.

3: Wp file manager plugin

The file manager plugin is another option to access your WordPress files. Follow the steps to access the files with the Wp file manager.

  • Install and activate WP file manager plugin
  • Go to File manager from WordPress Dashboard
  • WP-content>Themes>function.php
  • Download the file
  • Edit and upload to the same location

4: function.php file edit with default theme editor option

WordPress provides the option to edit the theme with the ‘theme editor’ option in the Appearance section.

  • Login to your WordPress dashboard
  • Appearance>Theme editor
  • Locate the function.php file
  • Edit and update file

If you have a child theme and a parent theme, edit the function file in the child theme (recommended). Because if you add the function in the parent theme, you will lose the functionality after the theme update.

Why child theme is important?

Child theme is the best way to edit and add functionality in your WordPress website. Functionality customisation is easy with child theme and developer can speedup the customisation with child theme.

If you are updating the parent theme function file then, your customisation will be lost after theme update or when you change your theme.

Bonus: Method to add code without editing the WordPress files

5: Code Snippets

By Adding the code with the Code Snippets plugin or any other site-specific plugin, you can store your functions without editing the theme files.

You can add your customized code and add the functionality to your website or blog. There are lots of benefits of adding the code with Code Snippets.

Benefits of using Code Snippets:

  • Store codes separately from function.php
  • Easy to use and good graphical interface
  • No effects when you change or update your theme
  • Deactivate the functions any time

Read: How to add custom code in WordPress with Code Snippets

I hope this tutorial helped you to understand the ways to edit WordPress function file. If you have any question or want to ask anything related to WordPress, please let us know.

Sharing is Caring

Don't forget to share with others. Thanks! 

My Name is Rashvinder Narwal, I am in Website design and development profession from 2015. I love to share my knowledge with my readers over 15+ blogs in English and Hindi language. Thanks !


Please enter your comment!
Please enter your name here