How to Remove WordPress Template Files

WordPress themes can be customized to tweak the design, add new features, or modify the theme structure, including the template files. Overriding a template file in the parent theme is one possible modification.


Although the WordPress Twenty Ten theme doesn’t provide a good example of this, there are reasons you would want to remove a parent theme's template file. Use your imagination a bit here to understand the process of removing a file from the parent theme with an example.


Imagine that you’re creating a child theme built off an Example Parent parent theme. Example Parent is well designed, and a great child theme was quickly built off it. The child theme looks and works exactly the way you want it to, but you have a problem.


The Example Parent theme has a home.php template file that provides a highly customized page template for use as the home page of your site. This works very well, but it isn't what you want for the site if you want a standard blog home page. If the home.php file didn't exist in Example Parent, everything would work perfectly.


You can’t remove the home.php file from Example Parent without modifying the parent theme (which you never, ever want to do), so you have to use a trick. Instead of removing the file, override the home.php file and have it emulate index.php.


You may think that simply copying and pasting the Example Parent index.php code into the child theme's home.php file would be a good approach. Although this would work, there is a better way: You can tell WordPress to run the index.php file so that changes to index.php are respected. This single line of code inside the child theme's home.php file is all you need to replace home.php with index.php:


<?php locate_template( array( 'index.php' ), true ); ?>

The locate_template function does a bit of magic. If the child theme supplies an index.php file, it is used. If not, the parent index.php file is used.


This produces the same result that removing the parent theme's home.php file would have. The home.php code is ignored, and the changes to index.php are respected.




dummies

Source:http://www.dummies.com/how-to/content/how-to-remove-wordpress-template-files.html

No comments:

Post a Comment