Sandesh

April 12, 2020

How To Add Custom PHP Code To WordPress

There are many times that you want to add custom PHP code ( custom functionality ) to WordPress/WooCommerce website. Ideally, developers know all the pros and cons of each method. Today, I will show you the best practices. You can use any of the above methods to add a code snippet to your website.

Method 1 – With Third-Party Plugin

 I will suggest a plugin Code Snippets. It will allow adding custom code quickly and safely. The custom code will work even after you switch the theme.

Method 2 – In Child Theme

There is no doubt that a child theme is the safest way of customization. Most of the themes provide a child theme, or you can create your own child theme within 10 minutes.

You just need to create two files, “functions.php” and “style.css”. Further, you can add PHP code snippets in “functions.php” file

Method 3 – Using WP Editor

WordPress contains a built-in editor that allows you to add a PHP or CSS code to your website. You can access the editor from the Dashboard -> Administration -> Appearance -> Editor. If you are not seeing Theme Editor, troubleshoot the same here.

Open the editor and go to the child theme’s functions.php. You can navigate to a child theme from the right-hand section. Add your code at the end of the “funtions.php” file. ( Before ?> this symbol, if you have it )

Method 4 – Using FTP

If you have access to cPanel of your website, you can use FTP client software like FileZilla to add custom code. Follow the given steps –

  1. Open your WordPress website via FTP.
  2. Go to wp-content -> themes -> your-child-theme.
  3. Right-click on functions.php and select View/Edit.
  4. Add your code at the end of the file and save it.
Sharing is Caring!
Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on telegram
Share on whatsapp

About the Author

Sandesh Jangam is Developer, WooCommerce Expert, and Podcaster. He is working as a WordPress developer since 2014 and helping people with this blog. He loves to travel ancient temples, chilling at the beach and reading books

Join 1,000+ Subscribers

Get exclusive access to WordPress, WooCommerce tips, articles, tutorials right in your inbox.​

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on telegram
Share on whatsapp

Leave a Comment

Your email address will not be published.

Become a WooCommerce Customization Expert and Earn More​

Get an early access notification right in your inbox.

Learn More or Register Now >>>