Skip to main content

Actions and Filters

Actions and Filters

Highlight and Share provides actions and filters so developers can customize behavior without editing plugin files. This document lists the hooks available in the plugin's PHP codebase.


Actions

has_enqueue_block_styles_scripts

Fires when the Click to Share block enqueues its styles and scripts in the block editor. Use this to enqueue your own block editor assets when the Highlight and Share block is in use.

/**
* Action: has_enqueue_block_styles_scripts
*
* Fires after Highlight and Share block styles/scripts are enqueued in the editor.
*/
add_action( 'has_enqueue_block_styles_scripts', function() {
// Enqueue custom block editor assets.
} );

Filters

has_social_network_defaults

Filter the default social networks array (labels, slugs, colors, share URL templates, etc.). Use this to add custom networks or modify built-in ones.

/**
* Filter: has_social_network_defaults
*
* @param array $social_networks The default social networks.
*/
add_filter( 'has_social_network_defaults', function( $social_networks ) {
// Add or modify networks.
return $social_networks;
} );

Example — modify the WhatsApp default (e.g. label, tooltip, or share URL):

add_filter( 'has_social_network_defaults', function( $social_networks ) {
if ( isset( $social_networks['whatsapp'] ) ) {
$social_networks['whatsapp']['label_text'] = __( 'Send via WhatsApp', 'your-text-domain' );
$social_networks['whatsapp']['tooltip_text'] = __( 'Send this via WhatsApp', 'your-text-domain' );
$social_networks['whatsapp']['share_url_template'] = 'https://api.whatsapp.com/send?text=%url%';
}
return $social_networks;
} );

has_show_{network_slug}

Determine whether a social network is shown. The filter name is dynamic: has_show_ + network slug (e.g. has_show_facebook, has_show_twitter, has_show_email). Built-in slugs include: facebook, twitter, linkedin, ok, vk, email, tumblr, copy, reddit, telegram, whatsapp, webshare, mastodon, threads, bluesky. Custom networks registered via has_social_network_defaults use their slug as well.

/**
* Filter: has_show_{network_slug}
*
* @param bool $enabled Whether the network is enabled (from plugin options).
*/
add_filter( 'has_show_facebook', function( $enabled ) {
return $enabled;
} );

has_show_facebook

Hide or show the Facebook sharing option.

/**
* Filter: has_show_facebook
*
* @param bool $show True to show Facebook, false to hide.
*/
add_filter( 'has_show_facebook', function( $show ) {
return $show;
} );

has_show_twitter

Hide or show the Twitter sharing option.

/**
* Filter: has_show_twitter
*
* @param bool $show True to show Twitter, false to hide.
*/
add_filter( 'has_show_twitter', function( $show ) {
return $show;
} );

has_show_linkedin

Hide or show the LinkedIn sharing option.

/**
* Filter: has_show_linkedin
*
* @param bool $show True to show LinkedIn, false to hide.
*/
add_filter( 'has_show_linkedin', function( $show ) {
return $show;
} );

has_show_ok

Hide or show the OK.ru sharing option.

add_filter( 'has_show_ok', function( $show ) {
return $show;
} );

has_show_vk

Hide or show the VK sharing option.

add_filter( 'has_show_vk', function( $show ) {
return $show;
} );

has_show_email

Hide or show the email sharing option.

/**
* Filter: has_show_email
*
* @param bool $show True to show email, false to hide.
*/
add_filter( 'has_show_email', function( $show ) {
return $show;
} );

has_show_tumblr

Hide or show the Tumblr sharing option.

add_filter( 'has_show_tumblr', function( $show ) {
return $show;
} );

has_show_copy

Hide or show the copy-to-clipboard option.

add_filter( 'has_show_copy', function( $show ) {
return $show;
} );

has_show_reddit

Hide or show the Reddit sharing option.

add_filter( 'has_show_reddit', function( $show ) {
return $show;
} );

has_show_telegram

Hide or show the Telegram sharing option.

add_filter( 'has_show_telegram', function( $show ) {
return $show;
} );

has_show_whatsapp

Hide or show the WhatsApp sharing option.

add_filter( 'has_show_whatsapp', function( $show ) {
return $show;
} );

has_show_webshare

Hide or show the Web Share API option.

add_filter( 'has_show_webshare', function( $show ) {
return $show;
} );

has_show_mastodon

Hide or show the Mastodon sharing option.

add_filter( 'has_show_mastodon', function( $show ) {
return $show;
} );

has_show_threads

Hide or show the Threads sharing option.

add_filter( 'has_show_threads', function( $show ) {
return $show;
} );

has_show_bluesky

Hide or show the BlueSky sharing option.

add_filter( 'has_show_bluesky', function( $show ) {
return $show;
} );

has_enable_content

Whether Highlight and Share runs on regular post or page content (e.g. inline highlighting and sharing).

/**
* Filter: has_enable_content
*
* @param bool $enable True to enable HAS on post content, false to disable.
*/
add_filter( 'has_enable_content', function( $enable ) {
return $enable;
} );

has_enable_excerpt

Whether Highlight and Share runs on post excerpts.

/**
* Filter: has_enable_excerpt
*
* @param bool $enable True to enable HAS on excerpts, false to disable.
*/
add_filter( 'has_enable_excerpt', function( $enable ) {
return $enable;
} );

has_highlight_sharing_enabled_for_post

Whether highlight-and-share (text selection sharing) is enabled for the current post.

/**
* Filter: has_highlight_sharing_enabled_for_post
*
* @param bool $enabled Whether highlight sharing is enabled for the post.
* @param int $post_id The current post ID.
* @since 7.0.0
*/
add_filter( 'has_highlight_sharing_enabled_for_post', function( $enabled, $post_id ) {
return $enabled;
}, 10, 2 );

has_headlines_enabled_for_post

Per-post override for headline sharing (sidebar share buttons on headings). Use to enable or disable headline sharing for specific posts.

/**
* Filter: has_headlines_enabled_for_post
*
* @param bool $global_enabled Global headlines enabled state for this context.
* @param int $post_id Current post ID.
* @return bool Whether headlines should run for this post.
*/
add_filter( 'has_headlines_enabled_for_post', function( $global_enabled, $post_id ) {
return $global_enabled;
}, 10, 2 );

has_headline_anchor_max_length

Purpose: Change the maximum character length used when truncating auto-generated headline anchors.

Parameters:

ParameterTypeDescription
$max_lengthintMaximum length (default 45). Returned value is cast to integer; values ≤ 0 disable truncation for that call.

Returns: int – The maximum length of characters to use for truncation.

Example: Use 60 characters instead of 45

add_filter( 'has_headline_anchor_max_length', function ( $max_length ) {
return 60;
} );

Example: Disable truncation via filter (e.g., for a specific context)

add_filter( 'has_headline_anchor_max_length', function ( $max_length ) {
// Only truncate on single posts; use full length elsewhere.
if ( ! is_singular( 'post' ) ) {
return 0;
}
return 45;
} );

Example: Longer limit for a specific post type

add_filter( 'has_headline_anchor_max_length', function ( $max_length ) {
if ( is_singular( 'handbook' ) ) {
return 80;
}
return $max_length;
} );

has_headline_anchor_truncated

Purpose: Modify the truncated slug after the plugin has shortened it (and stripped trailing dashes). Use this to apply custom logic or formatting to the final anchor.

Parameters:

ParameterTypeDescription
$truncatedstringThe truncated slug (no trailing dash).
$slugstringThe original full slug before truncation.
$max_lengthintThe maximum length that was used for truncation.

Returns: string – The slug to use as the heading ID. Must be non-empty; if empty, the plugin falls back to 'heading'.

Example: Add a prefix to truncated anchors only

add_filter( 'has_headline_anchor_truncated', function ( $truncated, $slug, $max_length ) {
// Only prefix when truncation actually occurred.
if ( strlen( $slug ) > $max_length ) {
return 'h-' . $truncated;
}
return $truncated;
}, 10, 3 );

Replace or add SVG sprite markup output in the footer (used for headline share panel icons when the main HAS container may not be present).

/**
* Filter: has_footer_svg_sprite
*
* @param string $svg Default empty string. Return SVG markup to output in footer.
*/
add_filter( 'has_footer_svg_sprite', function( $svg ) {
return $svg;
} );

has_headline_share_url_template

Modify the share URL template for a given network in the headline sharing panel (e.g. Twitter, LinkedIn). Placeholders like %url% and %title% are replaced by the front-end script.

/**
* Filter: has_headline_share_url_template
*
* @param string $template The share URL template for the network.
* @param string $slug The network slug (e.g. twitter, linkedin).
*/
add_filter( 'has_headline_share_url_template', function( $template, $slug ) {
return $template;
}, 10, 2 );

Example — use a custom share URL for WhatsApp in the headline sharing panel (placeholders such as %url% and %title% are replaced by the front-end script):

add_filter( 'has_headline_share_url_template', function( $template, $slug ) {
if ( 'whatsapp' === $slug ) {
return 'https://api.whatsapp.com/send?text=%url%';
}
return $template;
}, 10, 2 );

has_pin_show_on_archives

Whether image (pin) sharing is shown on archive and blog index pages.

/**
* Filter: has_pin_show_on_archives
*
* @param bool $show Whether to show image sharing on archives. Default true.
* @param string $post_type The post type (from get_post_type()).
*/
add_filter( 'has_pin_show_on_archives', function( $show, $post_type ) {
return $show;
}, 10, 2 );

has_pin_supported_post_types

List of post type slugs where image (pin) sharing is supported. Modify to add or remove post types.

/**
* Filter: has_pin_supported_post_types
*
* @param array $supported_slugs Array of post type slugs (e.g. post, page).
*/
add_filter( 'has_pin_supported_post_types', function( $supported_slugs ) {
return $supported_slugs;
} );

has_image_sharing_enabled_for_post

Whether image sharing (pin/share on images) is enabled for a specific post.

/**
* Filter: has_image_sharing_enabled_for_post
*
* @param bool $global_enabled Global enabled state from settings and post type.
* @param int $post_id The post ID.
*/
add_filter( 'has_image_sharing_enabled_for_post', function( $global_enabled, $post_id ) {
return $global_enabled;
}, 10, 2 );

has_pin_image_css_classes

CSS classes applied to the image sharing wrapper (e.g. position, show-on-hover). Add or remove classes.

/**
* Filter: has_pin_image_css_classes
*
* @param array $css_classes Array of CSS class strings (e.g. has-pin-image-wrapper, has-pin-top-left).
*/
add_filter( 'has_pin_image_css_classes', function( $css_classes ) {
return $css_classes;
} );

has_pin_core_exclusions

CSS classes or identifiers that exclude an image from getting the pin/image sharing wrapper. Images (or their parents) containing these strings are skipped. Default includes has-no-pin.

/**
* Filter: has_pin_core_exclusions
*
* @param array $core_exclusions Array of exclusion strings (e.g. has-no-pin).
*/
add_filter( 'has_pin_core_exclusions', function( $core_exclusions ) {
return $core_exclusions;
} );

has_pin_excerpt_exclusions

Same as has_pin_core_exclusions but applied only when processing excerpts. Use to add or remove excerpt-specific exclusions.

/**
* Filter: has_pin_excerpt_exclusions
*
* @param array $core_exclusions Array of exclusion strings for excerpt context.
*/
add_filter( 'has_pin_excerpt_exclusions', function( $core_exclusions ) {
return $core_exclusions;
} );

has_pin_show_on_excerpts

Whether image sharing is applied to post excerpts. Default true.

/**
* Filter: has_pin_show_on_excerpts
*
* @param bool $show Whether to show image sharing on excerpts. Default true.
*/
add_filter( 'has_pin_show_on_excerpts', function( $show ) {
return $show;
} );

Allow image sharing on featured images (post thumbnails) on singular posts/pages. Default false to avoid large hero images with sharing buttons.

/**
* Filter: has_enable_image_sharing_on_singular_featured
*
* @param bool $enable True to show sharing on singular featured images.
* @since 7.0.0
*/
add_filter( 'has_enable_image_sharing_on_singular_featured', function( $enable ) {
return $enable;
} );