If you are looking for ways to fix WordPress, especially from Stack Overflow you might be familiar with answers that suggest adding code to your WordPress functions to resolve issues on your WordPress-based website.
While the methods exist, how do you actually edit these functions? Do you have to use FTP? File Manager? A plugin? Or directly from the WordPress dashboard?
If you are still asking that, the answer is that you can add code to your WordPress functions via FTP, File Manager, a plugin, or directly from certain pages in your WordPress dashboard.
However, if you are using the Twenty Twenty-Two theme or newer, you might only be able to do this using a plugin. This is because some features in Twenty Twenty-Two based themes have been merged or removed, making it difficult for you to find or modify these functions.
How to Add Code to WordPress Functions
In this tutorial, we will add function code using the Hello Elementor theme. So, if you are using a different theme, make sure you know the name of your active theme.
It is highly recommended to only have two themes in your WordPress (the active theme and one default WordPress theme).
The function code we will add here is for hiding WordPress theme update notifications.
// Menyembunyikan notifikasi update theme WordPress - wpgan.comfunction wpgan_hide_theme_update(){global $wp_version;return(object) array('last_checked'=> time(),'version_checked'=> $wp_version,);}add_filter('pre_site_transient_update_themes','wpgan_hide_theme_update'); //Menyembuyikan notifikasi update theme WordPress - wpgan.comAdding Code to Functions via FTP
If you are not yet familiar with using FTP, you can follow the tutorial on the page How to Open cPanel File Manager via FTP.
After accessing the file manager using FTP, you can open your WordPress installation folder (usually in the public_html folder), then open the folder wp-content > themes > [nama theme aktif kalian].
Once you are in the active theme folder, look for the file functions.php, and edit that file to add the code you want. Once done, you just need to save it and upload the update to your server.
Adding Code to Functions via cPanel File Manager
To add code via cPanel, the method is almost the same as using FTP, where you just need to open the folder wp-content > themes > [nama theme aktif kalian] inside your WordPress installation folder.
To open the file manager, you can search for File Manager using the cPanel search bar, and your browser will automatically open a new tab to access the File Manager.
After you are inside the active WordPress theme folder, you can right-click on the file Functions.php, then click edit to add your code.
Adding Code to Functions via Theme File Editor
If you want to use the Theme File Editor, you only need WordPress admin access. Once you are in the WordPress dashboard, you can open the menu Appearance > Theme File Editor
After you are on the Theme File Editorpage, you can look for the menu Theme Function, then click that menu to open the functions.php editor.
Once you are in Theme Function, you can add your code at the very last line, then save the changes by clicking the button Update File.
Adding Code to Functions Using a Plugin
Actually, using a plugin is the easiest way and the one I often use. If you want to use a plugin, you can install the plugin WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager on your WordPress.
If the WPCode plugin is already installed, you can then open the menu Code Snippets > + Add Snippet from your WordPress dashboard.
Next, if you want to add custom code, you can choose the option Add Your Custom Code, or you can use the templates that are already available.
However, since we are using custom code here, choose the option Add Your Custom Code.
Here you can add your code snippet. For the name, you can give it something easy to remember, and for Code Type you can use the type of code you want to add, for example, CSS, HTML, JS, PHP, and so on.
However, because we are using PHP code here to hide the WordPress theme update notification feature, the Code Type should use PHP, then add your custom code and make sure the Toggle Inactive is changed to Active before saving the changes.
Conclusion
Actually, adding function code in WordPress is very easy to do, whether manually or using a plugin. However, to avoid errors from editing files, it is highly recommended to add code using a plugin. This way, you can immediately disable the snippet through the plugin settings page if an error occurs after adding the function code.
COMMENTS
Loading...