Finding a perfect theme for your WordPress site is a daunting task. On one hand you will have heavy themes integrated with shortcodes and page builder plugins. On other hand you can get lightweight themes that loads blazing speed. Whatever theme you choose, it is unlikely that you will get all functions in a single theme. In this article, we will explain how to edit WordPress theme and add your customizations.
Related: How to delete themes in WordPress?
WordPress Theme Files
Depending upon the structure, your theme may have different set of files. However, there are some template files most commonly used in all WordPress themes. For example, below are some of the important files available in twenty twenty-one WordPress theme.
- Style.css – contains all CSS style definitions for your theme
- Functions.php – here you can add functions and call core WordPress functions to make your theme work. This file acts as a plugin that enhances the features of core WordPress.
- Single.php – template file for single post
- Page.php – template file for single page
- Archive.php – template file for archive pages like categories and tags
- Header.php and footer.php – header and footer template files
What Features You Can Add in Theme Files?
There are many reasons you need to edit WordPress theme files. Here are some of the examples:
- If you are using Yoast SEO plugin, you need to add a function to enable breadcrumb.
- Insert AdSense or other advertisement codes.
- Add Google Analytics tracking code in header.
How to Edit WordPress Theme Files?
Before trying to edit files, make sure to understand the correct file you want edit. In most cases, you may need to edit functions.php file for adding additional functions to your theme. It is also common to add PHP code in single, header, footer or page templates. If you are not sure which file to edit, plat
There are three different ways to edit WordPress theme files.
1. Editing from WordPress Admin Panel
Follow the below instructions to edit theme files from WordPress admin panel.
- Login to your WordPress admin panel and navigate to “Appearance > Theme Editor” menu.
- WordPress will show you a warning message and click on “I understand” button to proceed further.
- Select your active theme from the “Select theme to edit”: dropdown.
- Choose the file from “Theme Files” section and edit from the content area.
- Click on “Upload Files” button to save your changes.
Note: If you are not seeing “Theme Editor” menu then check you have any security plugins. It is common to disable theme editor to avoid PHP file editing from the from end. Check out this article on how to disable or enable theme editor in WordPress admin panel.
2. Using File Manager App from Hosting Account
If you don’t like to edit file within admin panel, the alternate option is to edit from hosting account.
- Login to your hosting account and locate File Manager app.
- The app may be located in different categories depending upon the interface you use on your hosting account.
- Navigate to “wp-content” folder and go to “Themes” section.
- Click on your active theme name to find all theme template files.
- Edit the required files and update the content.
3. Remotely Editing with FTP
The last option is to remotely edit theme files using FTP client software like FileZilla. The advantage here is that you can use your favorite text editor to edit the content. For example, we use Brackets from Adobe. It will show you the syntax highlighting and help us to avoid missing tags.
- Launch your FTP client and connect to your webserver.
- Navigate to “/wp-content/themes/” folder and locate your active theme folder.
- After finding correct file, right click on it and select “Edit” option.
- Modify the content and reupload the file back to server.
Note: In all the above methods, you may need to clear the cache in order for the changes to be effective on the live site.
Risks in Editing Theme Files
There are multiple risks in editing theme files in your site.
Theme Update
Though you can edit a theme with different methods, you have the same risk in all the methods. Whenever you update a theme to next version all your changes will be wiped off. For example, you might have changed the heading color from red to blue in style.css file. After updating the theme, the heading will go back to the original red color on your site. This is the reason WordPress will warn you when you try to access theme files in admin panel.
Note: Remember, WordPress offers a custom section under “Appearance > Customize > Additional CSS” for adding custom CSS code. However, you can only add CSS here and you cannot modify the existing theme’s CSS. In addition, you can’t add functions or PHP code in the CSS section.
PHP Fatal Errors
Wrongly adding content in template files may break your site’s layout. For example, mistakes like leaving the PHP closing tag, forgetting comma or semicolon and adding a full stop in functions.php file will show you white screen of death. Therefore, make sure to follow the correct syntax when editing PHP code.
Alternate Options for Adding Functions
The best and recommended way of adding functions in WordPress site is to use a child theme. However, it will not help you in editing an existing function on your parent theme’s template file. Other option is to use WordPress Hook API and insert custom sections on your site which is not an easy task for normal users. However, themes like GeneratePress and Astra offers this as part of the theme so that you can insert custom functions.
Final Words
As mentioned, choosing the right theme is one of the daunting tasks when launching a WordPress site. many people strive for perfect theme and end up spending too much of time in adding custom functions. Later it will become a big maintenance task and you will not be able to manage at one point of time, Therefore, we strongly recommend choosing the best fit theme that offers good functions instead of editing theme files.
Leave a Reply
Your email is safe with us.