Using WordPress ’emoji_svg_ext’ PHP filter

The emoji_svg_ext WordPress PHP filter allows you to modify the file extension of emoji SVG files.

Usage

add_filter( 'emoji_svg_ext', 'your_custom_function' );

function your_custom_function( $extension ) {
    // your custom code here
    return $extension;
}

Parameters

  • $extension (string): The emoji file extension for SVG files. Default is ‘.svg’.

More information

See WordPress Developer Resources: emoji_svg_ext

Examples

Changing the emoji SVG file extension

Modify the file extension for emoji SVG files to ‘.customsvg’:

add_filter( 'emoji_svg_ext', 'change_emoji_svg_extension' );

function change_emoji_svg_extension( $extension ) {
    $extension = '.customsvg';
    return $extension;
}

Adding a custom prefix to the emoji SVG file extension

Add a prefix ‘_custom’ to the default emoji SVG file extension:

add_filter( 'emoji_svg_ext', 'add_prefix_emoji_svg_extension' );

function add_prefix_emoji_svg_extension( $extension ) {
    $extension = '_custom' . $extension;
    return $extension;
}

Changing the emoji SVG file extension based on user role

Change the emoji SVG file extension for users with the ‘editor’ role:

add_filter( 'emoji_svg_ext', 'change_emoji_svg_ext_for_editors' );

function change_emoji_svg_ext_for_editors( $extension ) {
    if ( current_user_can( 'editor' ) ) {
        $extension = '.editorsvg';
    }
    return $extension;
}

Changing the emoji SVG file extension for a specific emoji

Change the emoji SVG file extension only for the ‘grinning face’ emoji:

add_filter( 'emoji_svg_ext', 'change_grinning_face_emoji_svg_ext' );

function change_grinning_face_emoji_svg_ext( $extension ) {
    global $wp_emoji;
    if ( isset( $wp_emoji ) && 'grinning face' === $wp_emoji->name ) {
        $extension = '.grinningsvg';
    }
    return $extension;
}

Adding a timestamp to the emoji SVG file extension

Add the current timestamp as a suffix to the emoji SVG file extension:

add_filter( 'emoji_svg_ext', 'add_timestamp_emoji_svg_extension' );

function add_timestamp_emoji_svg_extension( $extension ) {
    $timestamp = time();
    $extension = $extension . '_' . $timestamp;
    return $extension;
}