Advertisement

What is WordPress hook? How it works? Advanced WordPress Theme Development Tutorial ( Part - 21)

What is WordPress hook? How it works? Advanced WordPress Theme Development Tutorial ( Part - 21) In WordPress theme and development, Hooks are functions that can be applied to an Action or a Filter in WordPress. Actions and Filters in WordPress are functions that can be modified by theme and plugin developers to change the default WordPress functionality.

Functions used to modify Actions/Filters in WordPress can be hooked into WordPress. However, it is important to note that actions and filters are not the same thing. Actions are functions performed when a certain event occurs in WordPress. Filters allow you to modify certain functions. Arguments used to hook both filters and actions look the same. But they are different in functionality and how they behave.

Example of a hook used with a filter in WordPress:

function wpb_custom_excerpt( $output ) {
if ( has_excerpt() && ! is_attachment() ) {
$output .= wpb_continue_reading_link();
}
return $output;
}
add_filter( 'get_the_excerpt', 'wpb_custom_excerpt' );
The sample code above creates a function wpb_custom_excerpt which is hooked into get_the_excerpt filter.

Example of a hook applied to an action:


function mytheme_enqueue_script() {
wp_enqueue_script( 'my-custom-js', 'custom.js', false );
}
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_script' );
The sample code above creates a function mytheme_enqueue_script which is hooked into wp_enqueue_scripts action.

See Details:

Visit: www.mwt.com.bd/
Like us:

This channel uploads all kinds of website design and development and search engine optimization as well as Freelancing tutorials. You can learn from this channel How to create a website? How to create WordPress Blog? Laravel Bangla Tutorial, WordPress Bangla Tutorial, Seo Bangla tutorial, WordPress Theme Customization.

WordPress,Bangla WordPress theme customization,Bangla WordPress plugin tutorial,

Post a Comment

0 Comments