What types of hooks are used in wordpress?
What types of hooks are used in wordpress?
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Aviance School is one of the largest web solutions platform in India for developers to learn and share their programming knowledge and build their careers.
In WordPress there are two types of hooks – Action Hooks and Filter Hooks.
1. Action Hooks:
Action hooks allow you to add additional code to the WordPress core or theme so that you can achieve some new functionality or new level of customizations.
Create a function in your theme’s functions.php file and hook it on using the add_action() function.
<?php
add_action( 'wp_head', 'aviance_actionhook_demo' );
function aviance_actionhook_demo () {
echo '<meta name="keywords" content="wordpress action hooks and filter hooks introduction" />' . "
";
} // End aviance_actionhook_demo()
?>
2. Filter Hooks:
Filter hooks are used to manipulate output. An example of this would be to add a line or text to the end of the content of each of your blog posts. Filter hooks can also be used for truncating text, changing formatting of the content.
<?php
add_filter( ‘wp_title’, ‘Add_sitename_to_wptitle’, 10, 2 );
Add_sitename_to_wptitle( $title, $sep ) {
/* Get website name. */
$name = get_bloginfo( ‘name’ );
/* Append website name to $title. */
$title .= $sep . ‘ ‘ . $name;
/* Return the title. */
return $title;
}
?>