How to Replace a Function With a Domain Name in Thesis
Thesis is a powerful WordPress framework that allows designers and users to customize the theme's layout and functionality with custom "hooks." Thesis hooks are just like WordPress template tags in that they allow you to create a custom function that contains any code you want and define a hook name that, when placed anywhere in your theme HTML, will display the function's results. To display a domain name or URL in any given place in your custom Thesis theme, a function must be created that contains the domain name, and a custom hook inserted in the theme's templates where you want the domain name to appear.
Instructions
-
-
1
Open your favorite HTML or text editor and create a new document. Save it somewhere easy to locate and name it "custom-functions.php." Make sure the "Save As..." file type is set to either "All Files" or the "PHP" file type.
-
2
Begin your document with the opening PHP tag:
<?php
Insert a few blank lines and then enter the closing tag:
?>
-
-
3
Place your cursor on the first blank line below your opening tag. Create a custom function using this basic syntax:
function custom_name() {
echo 'your code goes here';
}The word “function” tells WordPress that this is some code that can be executed and used in the theme. You would replace "custom_name" with any name you want, as long as it is unique. Use the underscore ( _ ) instead of a space. To ensure your name is unique, try adding your initials to the beginning. For example, a function for echoing a domain name might look something like this:
function my_domain() {
echo 'mydomain.com';
} -
4
Add a hook to your function on the next line using the "add_action" command:
add_action('thesis_hook','your_function');
For example, if you want the content of your function to appear on every page in the footer, you would use the footer hook:
add_action('thesis_hook_footer','my_domain');
Consult the Thesis User's Guide for a complete list of available hooks.
-
1
Tips & Warnings
If you don't want to use a Thesis hook to display your function content (domain name), you may use a standard PHP function call anywhere in your theme templates instead. For example:
<?php my_domain(); ?>
References
Resources
- Photo Credit Thinkstock/Comstock/Getty Images