Archives
- Newer posts
- November 2024
- April 2024
- November 2023
- October 2023
- August 2023
- May 2023
- February 2023
- October 2022
- August 2022
- July 2022
- May 2022
- April 2022
- March 2022
- February 2022
- June 2020
- March 2020
- February 2020
- January 2020
- December 2019
- November 2019
- October 2019
- September 2019
- August 2019
- July 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- December 2018
- November 2018
- October 2018
- September 2018
- August 2018
- July 2018
- June 2018
- May 2018
- April 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- September 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- August 2016
- June 2016
- April 2016
- March 2016
- February 2016
- January 2016
- July 2015
- June 2015
- Older posts
WordPress Theme Modification
A WordPress theme is a collection of templates and style sheets that determine the look of your website. WordPress provides a vast number of themes that you can install on your website. Be it be an e-commerce site, a portfolio site or just a blog site, you will get a theme for any kind of website you are building.
Most of the themes provide you with a look and feel that you want for your website. But sometimes you feel like you want to add something more or may be remove some existing theme features just to make it look perfect, and this is when you have to modify the existing theme according to your needs.
Modifying a WordPress theme is not an easy task. You have to be careful so that you do not break the existing theme. So you should follow certain practices to modify the theme without messing up with the existing theme functionality.
You should always start modifying your theme from the theme customizer. Most of the WordPress themes provide you with some basic customization functionality. You can access this customizer from the admin dashboard. Here you can change the name and logo of your site, set the page width, change the footer content, modify the menu, customize buttons, etc. Depending on the theme installed, the customization options available might vary.
If you feel the theme customizer does not provide you with all the options and you need to change the theme files, never ever go and change the original theme files directly. You might loose all your custom changes on a theme upgrade. Its always a good practice to create a child theme and add all the customization code in the child theme. This way you make sure that you do not break the original theme and do not loose your custom changes on theme up-gradation.
Creating a child theme is very easy. You can visit the following link for creating child theme. Child theme will consist of a functions.php and style.css file. All the custom css code will go in the child theme’s style.css file and in the functions.php file you will need to ensure the style.css file of both parent and child theme.
Sometimes you may feel that you need to change particular template file to change the look of a page. First check if you can achieve this by simply adding some css rules, if no then you can simply copy this template file to your child theme directory and override it. Keep in mind that you follow the directory structure while adding the file to your child theme and do not change the template name. This way the theme will use the template file in the child theme to display the page.
Some more advanced way to modify theme would be using hooks. Hooks allow you customize theme by adding or changing the default WordPress output. You can either use action hook or filter hook based on your need. Action hooks are triggered when a particular even occurs. For example, if you want to add some custom text to you footer you can use the wp_footer hook which adds code directly before the closing <body> html tag.
add_action(‘wp_footer’,’custom_function_name’);
function custom_function_name() {
echo “Your custom text here”;
}
add_action(‘wp_footer’,’custom_function_name’) will tell WordPress that you want to call custom_function_name function when the wp_footer action is triggered. Inside your custom function you can add the text that you want to display in the footer.
Similarly you can use the filter hook to modify the default content before it is displayed on the browser. Look at the following example.
function custom_excerpt_length( $length ) {
return 20;
}
add_filter( ‘excerpt_length’, ‘custom_excerpt_length’, 999 );
Using the excerpt_length hook you can change the no of words to display in the excerpt.
Many themes use custom hooks to make the code more extendable. You can make use of these custom hooks to modify the theme.
That’s all, these are some of the ways that you can follow while customizing your theme. Make sure you always create a child theme since it will always be easy for you to switch back to the original theme if your changes break something. Start with the theme customizer, go further and create child theme, add custom styles, override templates and use hooks to customize the theme. Hope this helps you.