You Might Not Need That WordPress Plugin

Do you find yourself asking, "Do I really need that WordPress plugin"?

WordPress plugins are a great way to quickly and easily add functionality to your WordPress website. However, running badly coded plugins can slow down your site, cause vulnerabilities, security issues and other problems. Below I have complied a list of snippets you can use that can offer the same functionality as some common plugins.

I don't discourage the use of plugins, however, I do discourage heavy and bloated plugins that include lots of unneeded functionality for a simple feature. Before installing a plugin you should ask yourself if you really need it and if the answer is "Yes" you should carefully read the reviews and check it is a good quality plugin.

You should experience less conflicts, bugs and see an improvement in speed after removing plugins that are not suitable. For some extra tips on optimizing the rest of your WordPress website check out this article: Cleaning Tips for WordPress Optimization.


Create custom post type

You can easily define Custom Post Types without the need of a plugin. Simply add this code to your functions.php file located in your theme folder to create a custom post type.

WordPressWordPress Codex Reference
if ( ! function_exists('register_books') ) {
  // Register our post type
  function register_books() {
    // Set label names for the WP backend UI
    $labels = array(
      'name'                => _x( 'Books', 'Post Type General Name', 'text_domain' ),
      'singular_name'       => _x( 'Book', 'Post Type Singular Name', 'text_domain' ),
      'menu_name'           => __( 'Books', 'text_domain' ),
      'parent_item_colon'   => __( 'Parent Book', 'text_domain' ),
      'all_items'           => __( 'All Books', 'text_domain' ),
      'view_item'           => __( 'View Book', 'text_domain' ),
      'add_new_item'        => __( 'Add New Book', 'text_domain' ),
      'add_new'             => __( 'Add New', 'text_domain' ),
      'edit_item'           => __( 'Edit Book', 'text_domain' ),
      'update_item'         => __( 'Update Book', 'text_domain' ),
      'search_items'        => __( 'Search Book', 'text_domain' ),
      'not_found'           => __( 'Not Found', 'text_domain' ),
      'not_found_in_trash'  => __( 'Not found in Trash', 'text_domain' )
    // Set post type options
    $args = array(
      'label'               => __( 'books', 'text_domain' ),
      'description'         => __( 'My list of books', 'text_domain' ),
      'labels'              => $labels,
      'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
      'taxonomies'          => array( 'category' ),
      'hierarchical'        => false,
      'public'              => true,
      'show_ui'             => true,
      'show_in_menu'        => true,
      'menu_position'       => 5,
      'menu_icon'           => 'dashicons-book',
      'show_in_admin_bar'   => true,
      'show_in_nav_menus'   => true,
      'can_export'          => true,
      'has_archive'         => true,
      'exclude_from_search' => false,
      'publicly_queryable'  => true,
      'capability_type'     => 'post'
    register_post_type( 'books', $args );
  add_action( 'init', 'register_books', 0 );

Generate sitemap.xml

You can automatically auto generate an XML sitemap for your website. A sitemap is important for search engines and SEO.

Add the below snippet to your functions.php file in your theme folder and every time you edit or add a new post or page a new sitemap.xml file will be generated in the root folder of your website for crawlers to access and index your site structure.

Be sure to add custom post types to the 'post_type' arguments.

Insipred by
add_action('publish_post', 'create_sitemap');
add_action('publish_page', 'create_sitemap');

function create_sitemap() {
  $sitemap_posts = get_posts(array(
    'numberposts' => -1,
    'orderby' => 'modified',
    'post_type'  => array('post','page'), // Add custom post types here
    'order'    => 'DESC'

  $sitemap = '<?xml version="1.0" encoding="UTF-8"?>';
  $sitemap .= '<urlset xmlns="">';

  foreach($sitemap_posts as $post) {

    $postdate = explode(" ", $post->post_modified);

  	$sitemap .= '<url>'.
      '<loc>'. get_permalink($post->ID) .'</loc>'.
      '<lastmod>'. $postdate[0] .'</lastmod>'.
  $sitemap .= '</urlset>';

  $fp = fopen(ABSPATH . "sitemap.xml", 'w');
  fwrite($fp, $sitemap);
Earn up to $7500 for one sale!

Create Shortcode

You can create your own shortcodes without the need of a plugin. These shortcodes can be used in pages and posts like so: [person name="John Smith" image="/images/people/john-smith.jpg" size="large"]

Add this code in your functions.php file located in your theme folder.

WordPressWordPress Codex Reference
// Return a simple string
// [foobar]
function foobar_func( $atts ) {
  return "foo and bar";
add_shortcode( 'foobar', 'foobar_func' );

// Return a string with attributes
// [foobar foo="HelloWorld"]
function foobar_func( $atts ) {
  $a = shortcode_atts( array(
    'foo' => 'Default value here if no value passed to parameter',
  ), $atts );
  return "foo = {$a['foo']}"; // foo = HelloWorld
add_shortcode( 'foobar_atts', 'foobar_func' );

// Using the example above return some HTML on to the page/post including the parameters defined in the shortcode
// [person name="John Smith" image="/wp-content/themes/mytheme/images/people/john-smith.jpg" size="large"]
function person_shortcode($atts) {
  $person = shortcode_atts( array(
    'name' => '',
    'image' => '/wp-content/themes/mytheme/images/people/no-image.jpg',
    'size' => 'large'
  ), $atts );
  return "<div class='person'><h3>{$person['name']}</h3><img src='{$person['image']}' alt='{$person['name']}' class='{$person['size']}'/></div>";
add_shortcode('person', 'person_shortcode');

Add Google Analytics Snippet

You can do this by directly editing and adding the snippet into your header.php file. However, it is generally advised not to touch the header.php file directly but instead hook into the head of your site with the wp_head hook and insert the snippet via your functions.php file in your theme folder.

function google_analytics() { ?>
  // Paste your own Google Analytics snippet below
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

    ga('create', 'UA-XXXXXXXX-XX', 'auto');
    ga('send', 'pageview');
<?php }
add_action( 'wp_head', 'google_analytics', 10 );

301 Redirects

You can add 301 redirects directly into your .htaccess file located in the root of your website.

Below is a simple example to redirect one page to another. There are many possible redirects you may want to implement, such as redirects using regex, these are all possible you just need to do a little research on how to implement it into your .htaccess file. You should not need a plugin create redirects.

Redirect 301 /old-page /new-page

Add custom CSS and JS

You don't need a plugin to add your own custom CSS or JS. Create your CSS and JS files in your theme folder and you can reference and enqueue them in your functions.php file located in your theme folder.

WordPressEnqueue CSS WordPress Codex Reference WordPressEnqueue JS WordPress Codex Reference
// Enqueue CSS and JS files
function custom_css() {
  // Enqueue a custom CSS file
  wp_enqueue_style('custom-css', get_stylesheet_directory_uri() . '/css/custom.css');
add_action('wp_enqueue_scripts', 'custom_css');

function custom_js() {
  // Enqueue a custom JS file with jQuery as a dependency
  wp_enqueue_script('custom-js', get_stylesheet_directory_uri() . '/js/custom.js', array('jquery'), false, false);
add_action('wp_enqueue_scripts', 'custom_js');

Note: JS files that have jQuery as a dependency need to be wrapped in the following function so you do not get a TypeError: $ is undefined error.

(function($) {
  // Your JavaScript/jQuery here
})( jQuery );

Implement SSL/HTTPS

When you have your SSL certificate connected to your domain you can have SSL/HTTPS set up in a few simple steps.

Change all urls to https in Settings ยป General in the WP admin, make sure both WordPress Address and Site Address have https:// at the start of the URL.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R,L]

To get SSL and HTTPS working on a WordPress multi-site admin area or login pages, you need to add the following code into your wp-config.php file:

define('FORCE_SSL_ADMIN', true);
WP Engine Managed WordPress Hosting

Enable GZIP Compression

You don't need a plugin to enable GZIP compression. Just paste the below snippet into your .htaccess file located in the root of your website.

WordPressWordPress Codex Reference
<IfModule mod_deflate.c>
# Insert filters
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE image/svg+xml

# Drop problematic browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary

More Coming Soon...

Got an idea to contribute? Tweet me

You should have basic WordPress and development knowledge to use these snippets. I am not responsible if it breaks your website.

Looking for a host that allows Git integrated WordPress deployments?