Using WordPress ‘print_emoji_styles()’ PHP function

The print_emoji_styles WordPress PHP function prints the important emoji-related styles.

Usage

To use the print_emoji_styles function, simply call it like this:

print_emoji_styles();

Parameters

This function has no parameters.

More information

See WordPress Developer Resources: print_emoji_styles

This function is implemented in WordPress since version 4.2.

Examples

Add emoji styles to the head of the document

This example adds the emoji styles to the head of your WordPress theme using the wp_head action.

// Add emoji styles to the head of the document
add_action('wp_head', 'add_emoji_styles');
function add_emoji_styles() {
    print_emoji_styles();
}

Remove default emoji styles and add custom ones

This example removes the default emoji styles and adds custom styles using the init action.

// Remove default emoji styles
remove_action('wp_print_styles', 'print_emoji_styles');

// Add custom emoji styles
add_action('init', 'add_custom_emoji_styles');
function add_custom_emoji_styles() {
    // Register the custom emoji styles
    wp_register_style('custom-emoji-styles', get_template_directory_uri() . '/css/custom-emoji-styles.css');

    // Enqueue the custom emoji styles
    wp_enqueue_style('custom-emoji-styles');
}

This example prints the emoji styles only on single post pages.

add_action('wp_head', 'conditionally_print_emoji_styles');
function conditionally_print_emoji_styles() {
    if (is_single()) {
        print_emoji_styles();
    }
}

Add emoji styles to a custom hook

This example adds the emoji styles to a custom hook named my_custom_hook.

// Add emoji styles to a custom hook
add_action('my_custom_hook', 'add_emoji_styles_to_custom_hook');
function add_emoji_styles_to_custom_hook() {
    print_emoji_styles();
}

This example prints the emoji styles directly in the HTML.

<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
    <meta charset="<?php bloginfo('charset'); ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?php wp_head(); ?>
    <?php print_emoji_styles(); ?>
</head>
<body <?php body_class(); ?>>