A WordPress functionality plugin sometimes called a site plugin is a special plugin designed to host theme independent code snippets that extend and customize the features of WordPress.
Most WordPress developers and tutorials found online instruct you to place custom code snippets into your theme’s functions.php file. Unfortunately, this is not always optimal. Instead you should only place theme specific functionality into your child theme’s functions.php file. Not code that is theme independent.
Why Use a Functionality Plugin?
I can think of two reasons:
- To avoid the the WordPress White Screen of Death. Have you ever copied a piece of code found in a WordPress tutorial, hit save and then found yourself staring at a white screen? I have, and chances are that you have too. For this reason alone, it’s worth considering the use of a WordPress Functionality plugin.
- To allow the website to change themes without losing overall website functionality.
- Example 1: You have a photography website and you used a code snippet that prevents WordPress from compressing your images upon upload. Just because you decided to change themes doesn’t mean you no longer want to prevent WordPress from compressing your images, right?
- Example 2: You decided to set WordPress post revisions to 5. If you placed that code snippet into your theme’s functions.php file and changed themes you will lose that functionality. But if you used a WordPress site functionality plugin, the settings are preserved.
A Starter WordPress Functionality Plugin
Check out the source code below for an example of a WordPress functionality plugin.
Lets start from the top and explain what is contained in our starter plugin.
Remove ‘Editor’ from ‘Appearance’ Menu
This stops users and hackers from being able to edit theme and plugin files from within the WordPress admin panel.
define( ‘DISALLOW_FILE_EDIT’, true );
Add the Ability to Use Shortcodes in Widgets
Many times we will want to execute a shortcode from a text widget. Out of the box WordPress does not allow you to execute a shortcode in a text widget. The code below makes it happen.
add_filter( ‘widget_text’, ‘do_shortcode’ );
Prevent WordPress from Compressing Images
Imagine you have a photography website and you tediously tweak your images before posting them to your WordPress website. Out of the box, WordPress will compress your image to 90% of it’s original file size. Most people would be okay with this, but not photographers.
add_filter( ‘jpeg_quality’, create_function( ”, ‘return 100;’ ) );
Disable Any and All Mention of Emoji’s
WordPress 4.2 introduced new emoji support. Most people don’t need or want it bloating their website. Thanks to Otto for supplying the code.
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’ );
Remove Items From <head>
Remove more code bloat from WordPress.
remove_action( ‘wp_head’, ‘wp_generator’ );
remove_action( ‘wp_head’, ‘wlwmanifest_link’ );
remove_action( ‘wp_head’, ‘rsd_link’ );
remove_action( ‘wp_head’, ‘wp_shortlink_wp_head’, 10, 0 );
remove_action( ‘wp_head’, ‘adjacent_posts_rel_link_wp_head’, 10, 0 );
Limit the Number of Post Revisions
By default, WordPress will keep an unlimited number of post revisions. We choose to limit our revisions to 5. Simply change the number 5 within the function to whatever you prefer and you’re all set. Do not change the number 10 found in the filter.
add_filter( ‘wp_revisions_to_keep’, ‘wpcc_set_revision_max’, 10, 2 );
$num = 5; //change 5 to match your preferred number of revisions to keep
The example plugin we detailed should get you moving along the way of separating code logically and efficiently. Take the code and tweak it for your specific needs.The article What is a WordPress Functionality Plugin? appeared first on RickRDuncan.com. It was published on and was last updated .