Blog2Social Hooks: Filters & Actions

Admin
2021-08-12 11:52

Introduction: What are hooks?

Hooks are being classified into "Actions" and into "Filters" and allow an almost unlimited extensibility and customizability of functions and appearances of software applications without having to edit or influence the core files of the software code at the same time.

The actual software code is not modified, instead the developer "hooks" his additional code to the respective "hook" (hook) provided by the WordPress system or other providers.

Implemented hooks remain intact even after updates to the original website code, e.g. the WordPress core or a plugin like Blog2Social, as even implemented customizations "hooked" via hook are not overwritten.

The use of child themes is also recommended, as these prevent the overwrites during updates from the used theme and its "functions.php" file.

In addition to the standard hooks integrated in WordPress, Blog2Social has developed its own hooks for web developers and customers. So also self-developed functions, can "hook" into processes and functions of Blog2Social to work with the Blog2Social WordPress plugin in the background and/or trigger functions (actions) or retrieve (filter).

Hooks are very useful for developers and IT-affine Blog2Social users to implement custom solutions with Blog2Social using self-developed functions.

 

Actions and Filters:

Action hooks allow you to insert custom code in different places (depending on where the hook is executed).
Filter hooks allow you to modify a variable that you pass in and pass the customized variable back.

When using 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
b2s_filter_posting_template_show_taxonomies* filter taxonomies >=6.8.2 Show custom taxonomies for selection in posting template
b2s_filter_posting_template_set_taxonomies* filter taxonomies, post_id >=6.8.2 Set custom taxonomies from other plugins or own template

 *available from Premium Business

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