# 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.

```php
/**
 * 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.

```php
/**
 * 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):

```php
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.

```php
/**
 * 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.

```php
/**
 * 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.

```php
/**
 * 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.

```php
/**
 * 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.

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

***

#### has\_show\_vk

Hide or show the VK sharing option.

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

***

#### has\_show\_email

Hide or show the email sharing option.

```php
/**
 * 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.

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

***

#### has\_show\_copy

Hide or show the copy-to-clipboard option.

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

***

#### has\_show\_reddit

Hide or show the Reddit sharing option.

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

***

#### has\_show\_telegram

Hide or show the Telegram sharing option.

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

***

#### has\_show\_whatsapp

Hide or show the WhatsApp sharing option.

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

***

#### has\_show\_webshare

Hide or show the Web Share API option.

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

***

#### has\_show\_mastodon

Hide or show the Mastodon sharing option.

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

***

#### has\_show\_threads

Hide or show the Threads sharing option.

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

***

#### has\_show\_bluesky

Hide or show the BlueSky sharing option.

```php
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).

```php
/**
 * 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.

```php
/**
 * 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.

```php
/**
 * 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.

```php
/**
 * 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:**

| Parameter     | Type  | Description                                                                                                    |
| ------------- | ----- | -------------------------------------------------------------------------------------------------------------- |
| `$max_length` | `int` | Maximum 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**

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

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

```php
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**

```php
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:**

| Parameter     | Type     | Description                                      |
| ------------- | -------- | ------------------------------------------------ |
| `$truncated`  | `string` | The truncated slug (no trailing dash).           |
| `$slug`       | `string` | The original full slug before truncation.        |
| `$max_length` | `int`    | The 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**

```php
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 );
```

#### has\_footer\_svg\_sprite

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).

```php
/**
 * 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.

```php
/**
 * 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):

```php
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.

```php
/**
 * 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.

```php
/**
 * 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.

```php
/**
 * 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.

```php
/**
 * 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`.

```php
/**
 * 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.

```php
/**
 * 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.

```php
/**
 * 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;
} );
```

***

#### has\_enable\_image\_sharing\_on\_singular\_featured

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

```php
/**
 * 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;
} );
```
