1. Home
  2. Knowledge Base
  3. How to Easily Use PHP Code on Your Website

How to Easily Use PHP Code on Your Website

In this knowledgebase article, we’re going to walk you through how to easily use the PHP code on your website.

The Problem with Editing Your Theme’s functions.php

One of the most important files you need to master is the functions.php file if you’re an aspiring WordPress developer. Also, if you’re either developing or modifying a theme, you need to know how to get the most out of your functions.php file.

Editing the functions.php file may seem easy to experienced users, but it can be quite tedious and intimidating for the newbies. They may face some pitfalls while inserting the PHP code in the functions.php file. The most common ones are as follows:

1 Not Update Proof

The main problem with editing functions.php file is it not being update proof unless used in the child theme.

2 Difficult to Keep Track

When you tweak your functions.php file, it becomes difficult to keep a track on all the changes made in the file.

3 Hard to Know Which Code Breaks the Functionality

A functions.php file can have numerous blocks of code used for many different purposes. Hence it becomes challenging to know which code breaks the functionality.

Solution: Use the Code Snippets Plugin

1 Install the Code Snippets Plugin

To begin with, install and activate the code snippets plugin by navigating to WordPress Dashboard > Plugins as shown below:

Install and activate Code Snippets plugin

2 Add the Snippet Code

Create a new snippet through the Add New page of the plugin. Each snippet has room for the code and a description to help you remember the code’s purpose.

You can add your snippet code by navigating to the Snippets section as shown below:

Using the code snippets plugin

As shown in the above image, add the title in the Title section. Once done, add the code snippet from our filters page in the Code section, and add the description section.

You can also notice some settings are available on the same page, which will help you configure when and where the code snippet should appear in your functions.php. You can select from the given list options, such as Run snippet everywhere, only run in the administration area, only run on-site front-end, only run once.

Finally, when your snippet is ready, click the Save Changes and Activate button to enable it. Alternatively, you can save it until you feel it’s ready to go live.

3 Manage the Snippets

You can manage your snippets from the All Snippets section. This allows you to see the status instantly and either activate or deactivate them.

Manage the Snippets

Adding code snippets to your WordPress website with the help of this plugin is extremely safe. Being able to easily see which snippets are active on your website and having a way to add the snippet without directly editing the functions.php file yourself can save you many problems down the road.

Let’s now have a close look how to make changes to your functions.php file.

How to Make Changes in functions.php File?

Note: We recommend you using child themes to completely revamp your site without having to modify any core or parent theme files. Making a coding mistake in your functions.php file can lead to other WordPress errors, such as a White Screen of Death. Hence, If you decide to edit your functions.php file, please use extreme caution to avoid the website’s adverse effects.

1 Navigate to the Theme Editor

To begin with, navigate to the Theme Editor, which is located under WordPress Dashboard > Appearance as shown below:

Navigate to the Theme Editor

2 Edit Your functions.php File

On the right-hand side of the screen, you can see a list of all the theme files. These differ depending on which theme you use, but one of the top options should be Theme Functions, i.e., functions.php file. Click on the file to open it in the editor as shown below:

Edit functions.php file

You can then make changes to your file and once done click on Update File.

If you have any questions about using the PHP code on your website easily, please feel free to contact our support team, we’re always more than happy to help.

Was this article helpful?

Still need help?

?

Submit Your Question

Please give us the details, our support team will get back to you.

Open Ticket