![]() ![]() The process of downloading and uploading files through any other FTP clients will generally be similar. You can use any other FTP client that you wish. For purposes of this tutorial, we are using the FileZilla FTP client. In this method, you will need to have an FTP client installed. Any theme updates will not affect the changes you make here. An example is shown below.Īfter activating the child theme, if you navigate to Appearance > Theme Editor and select the functions.php file you will be able to modify the functions.php file of the child theme. In your WordPress dashboard, navigate to Appearance > Themes and activate the child theme. If you have a child-theme, make sure it is activated. When you update your theme, the code that you added will be lost.īy default, the theme editor will open the functions.php file of the active theme. Most beginners and new website owners tend to use this method as they are usually not aware of the effect of updating themes. Adding code to a child theme’s function.php fileĪs mentioned, adding code to the parent theme’s files is not recommended as it is vulnerable to updates. However, sometimes you may need to add code to other files as well, for example, the theme’s header, in this case, you should select the header.php file instead of the functions.php file. Most of the time you will need to add code to the functions.php file. This is an easy method for adding PHP code to your WordPress website. If there are no errors the file will be updated. WordPress will usually check for any obvious format errors to your code before saving changes. Once you are done adding code to the file click on Update File. It is recommended to add code to the end of the file. This can be done by simply selecting all the code in the file and copying it to a text editor on your computer, for example, Notepad. Remember to take a backup of the file before you edit it. You can easily add code to the functions.php file. Step 3: Add PHP code to the functions.php file In the theme editor, search for the functions.php file on the right-hand side and click on it to open it. In your WordPress dashboard navigate to the Appearance menu and click on the Theme Editor as shown below: This will usually be your domain name followed by /wp-admin for example Step 2: Open the theme editor and the functions.php file Log in to your WordPress dashboard by visiting your admin URL. Step 1: Log in to your WordPress dashboard In this method we will add code to the theme’s functions.php file. We could simply skip this method, but we decided to include it for informational purposes. The only way to fix this will then be through FTP. If your website stops working, because you added the code with errors, you will not be able to roll back any changes. Often when adding code directly with the “Theme Editor”, if the code is not correct or conflicts with other resources on your website, you will end up crashing your website. This method is not recommended as it can easily break your website. Method 1: Adding PHP code with the built-in “Theme Editor” Method 1: Adding PHP code with the built-in “Theme Editor”.Here are 3 methods of adding PHP code to your WordPress website: You can easily add code to the child theme’s functions.php file and this will no be vulnerable to updates. It is therefore recommended to use a WordPress child theme. You may also lose the changes when you upgrade your WordPress version. You may miss out on critical security or bug fixes that are issued usually through updates to the theme or plugin. This can have undesirable effects on your website. Because of the lost changes users then tend not to update themes or plugins. This is not the best solution and while it may work, when you update your theme or plugin, your changes will be lost. Often code is placed in the parent theme’s functions.php file. Often when tweaking the code users tend to do it in the parent theme’s files. You can also add new functionality to WordPress using PHP and avoid the use of plugins. WordPress themes and plugins can easily be tweaked using PHP code. ![]() For example, when you want to add some additional functionality to your website or tweak the theme that you are using without changing the entire theme. However, often you will need to tweak the theme or plugin to suit your needs. ![]() It has thousands of themes and plugins to help you build any kind of website. WordPress is an amazing content management system and works seamlessly out of the box. ![]()
0 Comments
Leave a Reply. |