How to use WordPress’s file include functionality?

This article is all about to learn how to separate functions file by purpose in wordpress theme directory through include functions. Fir is far more of time you have been dwindling for how to mess up with different parameters of wordpress website and mostly you have found some reprise that it is the functions file that makes the most of wordpress customizations.

While performing customization of themes you also be aware that there is also large number of dedicated wordpress followers who also buy ready-made themes and while doing the modification on themes if you are happy enough to produce some of the most vitalized and wonderful theme then you can earn some money from it.

WordPress theme functionality makes it so powerful. Do not confuse oneself with posts, pages and other readable formats. In wordpress all these are kept separate and that makes the power of brilliant functionality and that makes the beauty of wordpress to go forward and provide additional customizations to it.

Each theme resides inside subdirectory of themes. One can install numerous themes but can only activate one theme at a time and that is the front end view of website. Theme is completely separated from wordpress core functions and files and that makes customization aspects of theme more and more powerful.

Then, comes the formats of wordpress theme framework which is now empowered with the creation of child themes, within the same theme parameters or framework and that makes the beauty of running theme so beautiful as there is no way that is going to corrupt the system files or core wordpress files and its functions.

In short we understand that it is the theme that provides the presentation of website in clean and neat manner. Due to complete separation from the core system file of wordpress there are chances and opportunities for developers to create more and more diversify and strategic fruitful wordpress theme customsations and improvements. Themes are divided into three components.

Its presentation formats are reside inside the file called as style.css and here one can add any of theme styles and modify it to suit better to the standards of legibility and provide ample opportunities for customizations.

Content has its provisions for articles, and information such as archive, categories, tags, search, posts, pages and so on. Here most of the times the articles and related wordpress information where the articles stays interacted with databases stays and most of these informations are for visitors and for search engine indexing.

The third but the most important and popular part of theme is logical part which is situated mostly inside functions.php. As a developer one could reach out to dynamic limits of eternal proportions with it with its inbounding high customization of theme functionalities.

This is the beauty of wordpress which is available for free with vast and dedicated followers and it is highly customization and you do not need to be a geek to do this as well as with due course of time, even you do not have an iota of idea when you have become a developer.

While developing a theme for my website I continue my endeavor to see how could I customize various themes, starting from twenty twelve, grand stand, sitepoint basic and thematic frame work and ultimately I do find the free to use thematic framework has been excellent in customization and in creating different websites for different needs of people.

I have found it becomes easier to use and add hooks and filters into wordpress functions.php so that different styles of wordpress themes with custom needs of customers. With due course of time as a developer I have found to be seen that the functions.php file becomes quite a bit prolonged document though it has some parts with comments so that the use of functions known to me but still I found it to be more complex so I do think of then to move some custom functionalities out of functions.php from child theme and then move it to another subdirectory so that these functions could be organized in a better way.

This is more of a useful tool that using this function as this is better way of recognizing functions, as most of these important functions are now in a completely separated ways from each other and this makes the customizations in the later time much better. Here, we should look forward towards an example code so that it should be better understood.

This way the functions functionalities becomes neat and way better understood even by novice users. Suppose we want to create a function that should provide the link to ours twitter link just below the article inside single.php. This means inside entire content of the article we wish to have the twitter link just below it so that when a visitor reads the post and if so then can continue to subscribe to twitter updates.

For this we create a subdirectory inside theme or child theme whichever you are using and then name it as a library. It is a folder. Then inside library sub folder or directory we create a file name as twitter-functions.php. Now open that files and pastes the sub functions code of twitter of anything like. I have given below one code snippet but you are not obliged to use the same code inside and you could write your own function code of twitter or search this from the internet to do this.

 

<?php

//Add a Twitter Link Under Each Post

function ittech_postfooter($output) {
 $twitterlink = '<p><a href="http://www.twitter.com/ittechs">Follow me on Twitter</a></p>';
 return ($twitterlink . $output);
} 
add_filter('thematic_postfooter','ittech_postfooter');

?>

// insted of ittechs use yours own twitter username

 

Here I use function as function ittech_postfooter, then in twitter link the twitter link and then the output and finally the adding of filter so that the function should provide the prominence to this function in add_filter and then end of function and in the beginning of the code beginning of the function code. Then save the witter-functions.php file there, inside theme’s subdirectory say library.

Now, how to include this functions inside functions.php file of theme file or child theme file which ever you are using currently. Next part is to add include function inside main functions.php file and this is very easy.
First note down the sub-directory of the file located inside, twitter-functions.php so that this should be included inside include functions of functions.php file. Open functions.php file in code editor and then paste

 

include('library/twitter-functions.php');

What you have done here is that you have separated the functions.php file completely and customized the entire functions so that you could recognize these functions whenever you find it.

Then, place the piece of the code inside subdirectory and then add that sub-directory inside include functions so that functions finds the root of the structure of the sub directory of functions file and what it makes is that you have avoided extra plugins as well as have avoided the functionality plugins even custom made so that there is hardly any chance of breaking of website in the case there is something wrong happens to custom functionality functions.

Where as with this now you have empowered your site to make the most of its productive ways to understand how you have made functions at different places and that makes updating and improvement of website pretty possible.

 

Related Post

This entry was posted in Wordpress Tutorial on by .

About Mohan Manohar Mekap

Mohan Manohar is a blogger from India who founded Ittech back in 2007. He is passionate about all things tech and knows the Internet and computers like the back of his hand.