Safe SVG icon
Media, Galleries & Sliders

Safe SVG hooks reference

  • By 10up
  • v2.5.2
  • Updated

Safe SVG 2.5.2 has 0 actions and 17 filters, read directly from its source code on Nov 17, 2026. The list updates automatically when a new version is released.

How to use these hooks

Actions let you run your own code at a specific moment. Filters let you change a value before the plugin uses it. Put your code in a child theme's functions.php or a code-snippets plugin, never in the plugin's own files, because updates overwrite them.

functions.phpyour child theme
// Change a value Safe SVG is about to use
add_filter( 'safe_svg_remove_remote_references', function( $value ) {
	// Change $value here.
	return $value;
}, 10, 1 );

Parts of a name in {braces} are filled in at runtime (for example a post type or field ID). Choose Example on any hook for a ready-to-edit snippet.

All hooks

  • includes/safe-svg-sanitizer.php line 126 · used in 2 places
    /**
     * Strip references to remote resources from the SVG.
     */
    apply_filters( 'safe_svg_remove_remote_references', false );
  • includes/safe-svg-sanitizer.php line 281
    /**
     * Determine if the current user can upload an svg.
     */
    apply_filters( 'safe_svg_current_user_can_upload', $can_upload );
  • safe-svg.php line 751
    /**
     * Calculate SVG dimensions and orientation.
     */
    apply_filters( 'safe_svg_dimensions', $dimensions, $svg, $attachment_id );
  • includes/blocks/safe-svg/register.php line 181
    /**
     * The wrapper class name.
     */
    apply_filters( 'safe_svg_inline_class', 'safe-svg-inline' );
  • includes/blocks/safe-svg/register.php line 248
    /**
     * The wrapper markup.
     */
    apply_filters( 'safe_svg_inline_markup', sprintf( '<div class="wp-block-safe-svg-svg-icon safe-svg-cover" style="text-align: %1$s;"> <div class="safe-svg-inside %2$s%3$s" style="width: %4$spx; height: %5$spx; background-color: var(--wp--preset--color--%6$s); color: var(--wp--preset--color--%7$s); padding-top: %8$s; padding-right: %9$s; padding-bottom: %10$s; padding-left: %11$s; margin-top: %12$s; margin-right: %13$s; margin-bottom: %... );
  • includes/blocks/safe-svg/register.php line 309
    /**
     * The styles applied inside the inline SVG's shadow root.
     */
    apply_filters( 'safe_svg_inline_shadow_styles', 'svg{fill:currentColor;width:100%;height:100%;max-width:100%;max-height:100%}', $attachment_id );
  • includes/blocks/safe-svg/register.php line 196
    /**
     * Whether to isolate this inline SVG inside a shadow root.
     */
    apply_filters( 'safe_svg_inline_use_shadow_dom', $has_stylesheet, $contents, $attachment_id, $has_stylesheet );
  • includes/safe-svg-sanitizer.php line 164
    /**
     * Filters the largest size a gzipped SVG may inflate to, in bytes.
     */
    apply_filters( 'safe_svg_max_inflated_size', $max_size );
  • includes/optimizer.php line 79
    /**
     * Filter to enable the optimizer.
     */
    apply_filters( 'safe_svg_optimizer_enabled', false );
  • safe-svg.php line 657
    /**
     * Calculate SVG dimensions and orientation.
     */
    apply_filters( 'safe_svg_pre_dimensions', false, $attachment_id );
  • includes/safe-svg-sanitizer.php line 247
    /**
     * Whether to also require that the user can read this specific attachment.
     */
    apply_filters( 'safe_svg_require_read_post', true, $attachment_id );
  • includes/optimizer.php line 97
    /**
     * Filter the params we pass to SVGO.
     */
    apply_filters( 'safe_svg_svgo_params', [ 'multipass' => true, ] );
  • includes/safe-svg-settings.php line 113
    /**
     * Filter the roles that can upload SVG files.
     */
    apply_filters( 'safe_svg_upload_roles', $upload_roles, $all_roles, $this );
  • safe-svg.php line 713
    /**
     * Decide which attributes of the SVG we use first for image tag dimensions.
     */
    apply_filters( 'safe_svg_use_width_height_attributes', false, $svg, $attachment_id );
  • includes/safe-svg-attributes.php line 25
    /**
     * var  array Attributes that are allowed.
     */
    apply_filters( 'svg_allowed_attributes', parent::getAttributes() );
  • includes/safe-svg-tags.php line 25
    /**
     * var  array Tags that are allowed.
     */
    apply_filters( 'svg_allowed_tags', parent::getTags() );
  • safe-svg.php line 416
    apply_filters( 'image_size_names_choose', array( 'full' => __( 'Full Size' ), 'thumbnail' => __( 'Thumbnail' ), 'medium' => __( 'Medium' ), 'large' => __( 'Large' ), ) );

Generated from Safe SVG's GPL-licensed source code. Hooks inside bundled third-party libraries are not listed.

Can't find the right hook?

We can build the customisation for you. Describe what you need: