Disable Emoji Processing

Sometimes WordPress translates special characters into images when I want those characters left alone. After a little digging, I learned that this was being done by the emoji translation scripts.

First I tried disabling this feature from the admin panel, but the characters were still being converted. Disabling the translation scripts in functions.php did the trick for me.

To disable the emoji translation scripts, add the following lines to your functions.php file:

function disable_emojis() {
   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_action( 'admin_print_styles', 'print_emoji_styles' );   
   remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
   remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );  
   remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
}
add_action( 'init', 'disable_emojis' );

Disable Automatic <p> Insertion

WordPress substitutes newlines with <p> tags by default in posts and pages. That feature is generally more trouble than it is worth if you know even a little HTML.

To disable <p> tag insertions, add the following lines to your functions.php file:

remove_filter('the_content', 'wpautop');
remove_filter('the_excerpt', 'wpautop');
remove_filter('the_title',   'wpautop');

Unwanted <head> Links

The default behavior adds a slew of tags to the document <head> that either break W3C validation, aren’t of much use, or both.

To prevent those tags from being injected into the <head>, add the following lines to your functions.php file:

function removeHeadLinks() {

   // KEEP THESE TWO IF YOU USE OUTSIDE BLOG EDITING SOFTWARE (LIKE WINDOWS LIVE WRITER)
   remove_action('wp_head', 'rsd_link');
   remove_action('wp_head', 'wlwmanifest_link');

   // NO NEED FOR THIS AT ALL.
   // DISPLAYS WP VERSION, WHICH IS NOT SUCH A GOOD IDEA SECURITY-WISE
   remove_action('wp_head', 'wp_generator');

   // REMOVES LINK TO REST API
   remove_action('wp_head', 'rest_output_link_wp_head');

   // REMOVES LINKS TO XML/JSON OEMBED DATA
   remove_action('wp_head', 'wp_oembed_add_discovery_links');
}

add_action('init', 'removeHeadLinks');

Debug Mode

If you use third-party plugins, or if you’re in the process of developing a theme, enabling debug mode is a very handy feature.

When debug mode is enabled, script errors and their corresponding files and line numbers will be inserted into the HTML output. Of course, once your installation has been fully debugged, set WP_DEBUG to false for security and enhanced performance.

To enable/disable debug mode, add the following line to wp-config.php:

// MAKE SURE THIS IS false BEFORE THE BLOG IS IN PRODUCTION
define('WP_DEBUG', true);
define('WP_DEBUG_DISPLAY', true);

Miscellaneous

Blocking External Access to XML-RPC Service

WordPress provides an XML-RPC API for managing your blog with other programs. In general, there’s nothing wrong with that — I use VimRepress to manage this WordPress blog. The problem is that when the XML-RPC API is exposed to the web, many bots will use it to post comment spam.

Since I only edit my blog from the LAN, I set up a few access rules in my Apache <VirtualHost> to block outside access to xmlrpc.php.

To restrict XML-RPC API access to the local area network, add the following lines inside the <Directory> tag of the <VirtualHost> config for your WordPress blog.

# NOTE: This is Apache 2.4 syntax.  The syntax is different for earlier versions of Apache.
<Files xmlrpc.php>
   Require ip 192.168.0.0/16
   Require ip 10.0.0.0/8
   Require ip 127.0.0.1
</Files>

Deleting Unwanted Post Revisions

By default, WordPress will keep revision histories of blog posts and pages. This feature has saved my bacon on several occasions. The only down side is that it will eventually choke your database up with stale revisions.

If you ever need to purge those stale revisions from the database, just run this SQL statement on your WordPress database:

DELETE FROM wp_posts WHERE post_type = 'revision';

Further Reading

If you manage your own WordPress installation(s), reading the Editing wp-config.php article at wordpress.org from top-to-bottom wouldn’t hurt:

https://codex.wordpress.org/Editing_wp-config.php


← Older Newer →

Leave a Reply

You must be logged in to post a comment.