This is Tutorial 3 in a series of Thesis tutorials. We will create a new function here and learn how to implement it in the Thesis theme. This will give the beginner user an insight on how to start customizing the Thesis theme in amazing ways.
In the previous tutorial we learnt about custom.css and custom_functions.php and what roles they play in customizing the Thesis theme. It is advisable that you read that tutorial before you attempt to follow this tutorial (but only if you are a beginner user).
Before we go ahead and create a new function and try to execute it, we need to learn a little bit about Hooks. What are Hooks? Let me try to explain in layman terms before getting too technical. A web-page – it has a lot of sections inside of it – like the header, the body, the footer etc. etc. Now if you imagine that you can access these different sections inside the webpage by magically using a keyword for each part of the section, wouldn’t that be wonderful? For example – consider the header of the web-page which has the logo and the tagline etc. and if say you wanted to add something to it at the end (of the header) and to do that, all you had to do was use the magic word “after header” …. that would be so easy, woudn’t it? Well, these points do exist inside the webpage and are referred as Hooks in Thesis terms.
Thesis provides a wide range of Hooks which target just about every part of the web-page. There are as more than 60 Hooks that can be used in a Thesis theme, complete list of which can be found here – List of Thesis Hooks.
The following diagram can be used to visualise the concept of hooks (click for a bigger image) -
So, now we understad what Hooks are. Let us now write a function and then use a Hook to execute this function at this particular Hook in the web-page. Premise of the function we are writing today – A copyright message in the footer which is a usual requirement in most web-pages. To achieve this, we will create a function that will display “© 2011 – All Rights Reserved”, to output the symbol of copyright, we will use its HTML equivalent which is -> ©. So lets get started -
Creating the Function :
The name of our function will be “my_copyright”. The following is the code for the function. Each line of the code will be explained below the actual code. © 2011 - All Rights Reserved © 2011 – All Rights Reserved
function my_copyright() {
echo "
}
function my_copyright() : This defines my_function() as a function.
echo “
So now we have written our function. We need to execute the function now. To do this we need to know the Hook that we will be using, so here goes -
Executing the Function :
add_action('thesis_hook_footer', 'my_copyright');
Yes you guessed it right. The add_action is actually a PHP function which takes 2 arguments. The first argument is the name of the Hook, and the next argument is the name of the function we wrote. All this code goes into the custom_functions.php file. Once you have inserted this code into the custom_functions.php file and saved it, the copyright messages will now be visible in the footer in all the pages! Neat huh?
Since the footer is displayed in all the pages, each time the footer is being created in the web-page, Thesis checks for custom functions and executes our newly written function.
Hope you enjoyed this tutorial!! If you have any questions at all – feel free to post it in the comments and I’ll get back to you!
Check out the other Thesis tutorials in this website -
Thesis tutorial part 1 : installation of the Thesis theme
Thesis tutorial part 2 : learning about customizing
Pingback: Wordpress Thesis Tutorial, custom footer, CSS styling
Pingback: Thesis tutorial part 2 : learning about customizing
Pingback: Thesis tutorial part 1 : installation of the Thesis theme
Pingback: Thesis Tutorial Part 5 : adding different ribbons in blog post
Pingback: Thesis tutorial part 7: add ShareThis button to the post
Pingback: Thesis tutorial part 6: adding Facebook Like Box | Love For Tech
Pingback: Wordpress Thesis quick tip: changing the teaser excerpt size | Love For Tech