Overview of available plugin hooks.
Hook | Type | Description |
---|---|---|
sti_buttons_array | filter | Filter sharing buttons that must be displayed |
sti_exclude_current_page | filter | Exclude or not current page from sharing |
sti_js_custom_data | filter | Custom data to use inside js |
sti_js_plugin_data | filter | Filter plugin settings for JS |
sti_shortcode_output | filter | Filter output of the image shortcode |
sti_buttons_shortcode_params | filter | Filter sharing data for buttons shortcode |
sti_buttons_shortcode_output | filter | Filter html output of buttons shortcode |
sti_svg_icons | filter | Filter svg icons |
sti_all_options | filter | Filter plugin options for the settings page |
apply_filters( 'sti_buttons_array', (array) $buttons );
Filter sharing buttons that must be displayed for each image on the page.
Let's show different sharing buttons for the Shop
page.
add_filter( 'sti_buttons_array', 'my_sti_buttons_array' ); function my_sti_buttons_array( $buttons ) { if ( is_shop() ) { $buttons['desktop'] = array( "facebook", "twitter", "linkedin" ); $buttons['mobile'] = array( "telegram", "facebook", "twitter" ); } return $buttons; }
apply_filters( 'sti_exclude_current_page', (bool) $exclude );
Choose to exclude or not current page from the sharing.
Exclude from sharing all images on page with ID 7901
add_filter( 'sti_exclude_current_page', 'my_sti_exclude_current_page' ); function my_sti_exclude_current_page( $exclude ) { if ( get_queried_object_id() === 7901 ) { return true; } return $exclude; }
apply_filters( 'sti_js_custom_data', (array) $custom_data );
Custom data to use inside js. For example, can be used to change social buttons icons or customize shared content.
Change default icon for Facebook sharing with the custom one.
add_filter( 'sti_js_custom_data', 'my_sti_js_custom_data' ); function my_sti_js_custom_data( $custom_data ) { $custom_data['buttons']['facebook'] = array( 'icon' => '<svg aria-hidden="true" focusable="false" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M275.9 330.7H171.3V480H17V32h109.5v104.5l305.1 85.6V480H275.9z"></path></svg>;', ); return $custom_data; }
apply_filters( 'sti_js_plugin_data', (array) $sti_vars );
Filter plugin settings for JS. Can be used to change the settings that are specified from the plugin settings page.
Let's change buttons default position for mobile devices.
add_filter( 'sti_js_plugin_data', 'my_sti_js_plugin_data' ); function my_sti_js_plugin_data( $sti_vars ) { if ( wp_is_mobile() ) { $sti_vars['mobile_icon'] = false; $sti_vars['position'] = 'after'; } return $sti_vars; }
apply_filters( 'sti_shortcode_output', (string) $output, (array) $atts );
Filter output of the sti_image
shortcode.
Wrap output with .wrapper
div block.
add_filter( 'sti_shortcode_output', 'my_sti_shortcode_output', 10, 2 ); function my_sti_shortcode_output( $output, $atts ) { $output = '<div class="wrapper">' . $output . '</div>'; return $output; }
apply_filters( 'sti_buttons_shortcode_params', (array) $params, (array) $atts );
Filter sharing data for sti_buttons
shortcode.
image
, title
, description
and url
that will be shared.For specific image my_image.png
set sharing title to My custom title
add_filter( 'sti_buttons_shortcode_params', 'my_sti_buttons_shortcode_params', 10, 2 ); function my_sti_buttons_shortcode_params( $params, $atts ) { if ( $atts['image'] === 'my_image.png' ) { $params['data-title'] = 'My custom title'; } return $params; }
apply_filters( 'sti_buttons_shortcode_output', (string) $output, (array) $atts );
Filter output of the sti_buttons
shortcode.
Wrap output with .wrapper
div block.
add_filter( 'sti_buttons_shortcode_output', 'my_sti_buttons_shortcode_output', 10, 2 ); function my_sti_buttons_shortcode_output( $output, $atts ) { $output = '<div class="wrapper">' . $output . '</div>'; return $output; }
apply_filters( 'sti_svg_icons', (array) $icons );
Filter svg icons that are used inside the admin settings page.
Change default icon for Facebook sharing with the custom one.
add_filter( 'sti_svg_icons', 'my_sti_svg_icons' ); function my_sti_svg_icons( $icons ) { $icons['facebook'] = '<svg aria-hidden="true" focusable="false" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M275.9 330.7H171.3V480H17V32h109.5v104.5l305.1 85.6V480H275.9z"></path></svg>;'; return $icons; }
apply_filters( 'sti_all_options', (array) $options );
Filter plugin options that are used for the settings page. Options array is divided by settings tabs ( general, content, ... ).
Add Instagram
button and Instagram account
options for the plugin settings page.
add_filter( 'sti_all_options', 'my_sti_all_options' ); function my_sti_all_options( $options ) { foreach ( $options as $tab_name => $tab_options ) { if ( 'general' === $tab_name ) { foreach( $tab_options as $tab_option_key => $tab_option ) { if ( isset( $tab_option['id'] ) && $tab_option['id'] === 'buttons' ) { $options[$tab_name][$tab_option_key]['choices']['instagram'] = array( 'name' => __( "Instagram", "share-this-image" ), 'desktop' => 'true', 'mobile' => 'true' ); } } } } $options['general'][] = array( "name" => __( "Instagram account", "share-this-image" ), "desc" => __( "Set instagram account name.", "share-this-image" ), "id" => "instagram_account", "value" => '', "type" => "text" ); return $options; }