Blog2Social Hooks: Filters & Actions

Admin
2020-05-25 12:59

Introduction: What are hooks?

Hooks in WordPress allow you to change or add code without editing core files. They are used extensively throughout WordPress and Blog2Social and are very useful for developers.

There are two types of hook: actions and filters:

  • Action Hooks allow you to insert custom code at various points (wherever the hook is run).
  • Filter Hooks allow you to manipulate and return a variable which it passes.

 

Using hooks

If you use a hook to add or manipulate code, you can add your custom code to your theme’s functions.php file.

Using action hooks

To execute your own code, you hook in by using the action hook "do_action('action_name');".
Here is where to place your code:

add_action( 'action_name', 'your_function_name' );
function your_function_name() {
// Your code
}

Using filter hooks

Filter hooks are called by using the code “apply_filter( 'filter_name', $variable )”.
To manipulate the passed variable, you can do something like the following:

add_filter( 'filter_name', 'your_function_name' );
function your_function_name( $variable ) {
// Your code
return $variable;
}

With filters, you must return a value.

 

Action and Filter Hook Reference

This is a list of action and filter hooks found within Blog2Social files:

Hook Type Params B2S-Version Info
b2s_og_meta_title filter title >=5.3.0 OG Meta Tag Title
b2s_og_meta_desc filter desc >=5.3.0 OG Meta Tag Description
b2s_og_meta_image filter image_url >=5.3.0 OG Meta Tag Image
b2s_card_meta_title filter title >=5.3.0 Twitter Cards Tag Title
b2s_card_meta_desc filter desc >=5.3.0 Twitter Cards Tag Description
b2s_card_meta_image filter image_url >=5.3.0 Twitter Cards Tag Image
b2s_card_meta_type filter type >=5.3.0 Twitter Cards Tag Type
b2s_filter_wp_user_post_author_display_name filter name, author_id >=6.0.0 Post-Template: Wordpress Post Author Name
b2s_filter_wp_post_hashtag filter post_id >=6.4.0 Hashtags from the post
b2s_filter_wp_post_image filter images, post_id >=6.5.0 Change image with filter function

 

Relevant Links:
https://codex.wordpress.org/Plugin_API/Hooks

Test Blog2Social 30 days free of charge

Action, Filter, Hooks

Average rating: 3 (2 Votes)

You cannot comment on this entry