質問

So WP 4.2 introduced emojis (smileys) that basically adds JS and other junk all over your pages. Something some people may find shocking. How does one completely erase all instances of this?

役に立ちましたか?

解決

We will hook into init and remove actions as followed:

function disable_wp_emojicons() {

  // all actions related to emojis
  remove_action( 'admin_print_styles', 'print_emoji_styles' );
  remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  remove_action( 'wp_print_styles', 'print_emoji_styles' );
  remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
  remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
  remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );

  // filter to remove TinyMCE emojis
  add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
}
add_action( 'init', 'disable_wp_emojicons' );

We will need the following filter function to disable TinyMCE emojicons:

function disable_emojicons_tinymce( $plugins ) {
  if ( is_array( $plugins ) ) {
    return array_diff( $plugins, array( 'wpemoji' ) );
  } else {
    return array();
  }
}

Now we breathe and pretend this feature was never added to core... particularly while tons of resolved bugs are yet to be implemented.

This is available as a plugin, Disable Emojis.

Alternatively, you can replace the smilies with the original versions from previous versions of WordPress using Classic Smilies.

Update

We can also remove the DNS prefetch by returning false on filter emoji_svg_url (thanks @yobddigi):

add_filter( 'emoji_svg_url', '__return_false' );

他のヒント

Better solution if you want to disable this: use a plugin.

Same code as from Christine's comments: https://wordpress.org/plugins/disable-emojis/

Same code that also fixes the smilies to be the older ones: https://wordpress.org/plugins/classic-smilies/

Source: Me, since I wrote that code in the first place. https://plugins.trac.wordpress.org/changeset/1142480/classic-smilies

This is the simple way to remove emoji. Add bellow code to your function.php

remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' ); 

If you want to prevent Wordpress from automatically converting your old school ASCII smilies to Unicode emojis (like ;-) to 😉) in your posts altogether, you might want to remove_filter('the_content', 'convert_smilies')

(Not 100% sure this is what the question's about, but this solved my problem and I hope it might be handy for someone.)

Good news, I added a feature request:

Introduce a new option to WordPress WP_EMOICONS in here https://core.trac.wordpress.org/ticket/38252

and apparently this has been marked as duplicate https://core.trac.wordpress.org/ticket/32102 so we may expect something like

define( 'WP_EMOICONS', false );

in the future WordPress releases.

I've tried some codes above but the only codes works on my end is this one.

Don't forget to back-up your functions.php before implementing these codes.

// REMOVE WP EMOJI
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');

remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );

Since WordPress emoji are served from s.w.org and they are not compressed, this impacts the SVG loading time depending on how many emoji you are using, and can even throw warnings on Google’s PageSpeed Insights tool.

To fix this issue, you can serve the emoji directly from your WordPress site itself and not by making external calls through js.

This can be achieved by installing the plugin Compressed Emoji which is available for free in the WordPress.org plugin repository.

When the plugin is activated, the compression offers savings in the range of 3kb ~ 1.3kb (roughly %60) per emoji.

Source: WPTavern

ライセンス: CC-BY-SA帰属
所属していません wordpress.stackexchange
scroll top