10 WordPress Tricks & Tips to Help You Manage Your Blog

WordPress is evolving – I think that’s already a generic way of opening a blog post about WordPress. I’m not gonna invent anything new right now, but I’ll say that these tips and tricks have been curated specifically to help you manage your WordPress blog in a more efficient way.

I’ve worked with WordPress for several years now, I’ve launched multiple successful sites with it, and I’ve made more money from my WordPress sites that I have in any other job so far. It’s obviously a great platform, and while by default it’s fully functional and ready to go, we can use snippets, tips and tricks to optimize our workflow.

The (self-hosted) WordPress project has a separate website, called the WordPress Codex. It’s a site that hosts all of the information regarding the technical aspects of WordPress, including code previews, configurations and more. Learn Codex, and you’ll learn WordPress. It’s more than just a platform for pushing the ‘Publish’ button, it’s time to tap into that power!

By itself, the project is slowly moving forward. The newly released WordPress 3.9 ‘Smith’ version, introduced some cool stuff like revamped post editor, and additional features for managing your media files. But, there is definitely room for improvement, and perhaps we can use these tips and tricks to mimic it.

WP Theme Standardization Panel

It’s a GitHub project that aims to standardize WordPress theme hooks.

felixarntz wp theme standardization panel

Grab the EXIF metadata for Images

You can do this by default, but the output isn’t nicely formatted, you can use the following snippet to properly get the EXIF data, in a readable output.

< ?php
function plugin_get_attachment_image_meta( $id )
{
  $meta = wp_get_attachment_metadata( $id );
  if( is_array( $meta ) && isset( $meta['image_meta'] ) )
  {
    $meta = $meta['image_meta'];
    if( isset( $meta['focal_length'] ) && !empty( $meta['focal_length'] ) )
    {
      $meta['focal_length'] = $meta['focal_length'] . 'mm';
    }
    if( isset( $meta['shutter_speed'] ) && !empty( $meta['shutter_speed'] ) )
    {
      $meta['shutter_speed'] = '1/' . absint( 1.0 / floatval( $meta['shutter_speed'] ) ) . 's';
    }
    if( isset( $meta['aperture'] ) && !empty( $meta['aperture'] ) )
    {
      $meta['aperture'] = sprintf( 'f%.1f', $meta['aperture'] );
    }
    if( isset( $meta['iso'] ) && !empty( $meta['iso'] ) )
    {
      $meta['iso'] = 'ISO' . $meta['iso'];
    }
    return $meta;
  }
  return null;
}

Validate Posts Images Source

If you're tinkering with WordPress a lot, chances are, you've at some point deleted images either by accident, or because you used the wrong plugin at the wrong time. By using this script, you'll be able to scan your database and the uploads folder to match up any missing images.

We never really think of these things, but sometimes it's worth doing a quick check, just to see how well we're performing.

Header Information Standard for Templates

Admit it, you've probably tried to come up with your own version of this at least a couple of times, and probably not just for WordPress, but your own projects too. It's always nice to use what others are using, so here is a template that you can use for your next WordPress theme you're going to develop.

/*
Theme Name: [theme]
Author: [author]
Author URI: [url]
Theme URI: [theme-url]
Version: [ver]
Description: [theme-name] - [description]
Copyright: [(c) (year) (company)]
License: [license]
License URI: [license-url]
Tags: [tag1, tag2, tag3]
*/

You obviously need to remove the [] brackets.

How to Change HTTP Headers in WordPress (Content-Type)

function changeHeaders($headers)
{
    $headers['Content-Type'] = 'application/json; charset=utf-8';

    return $headers;     
}
add_filter('wp_headers', 'changeHeaders');

Hide Your WordPress Information from Public

If you’re cautious of your own blog, and don’t want everyone to be snooping around and trying to copy your creation, you can put the following script in your functions.php file, it will remove all the ‘giveaway’ data from the source, preventing ‘beginners’ from learning what your site is based on.

remove_action('wp_head', 'wp_generator');

function disable_our_feeds() {
    wp_die( __('Error: No RSS Feed Available, Please visit our homepage.') );
}

add_action('do_feed', 'disable_our_feeds', 1);
add_action('do_feed_rdf', 'disable_our_feeds', 1);
add_action('do_feed_rss', 'disable_our_feeds', 1);
add_action('do_feed_rss2', 'disable_our_feeds', 1);
add_action('do_feed_atom', 'disable_our_feeds', 1);

function roots_head_cleanup() {
  remove_action('wp_head', 'feed_links', 2);
  remove_action('wp_head', 'feed_links_extra', 3);
  remove_action('wp_head', 'rsd_link');
  remove_action('wp_head', 'wlwmanifest_link');
  remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
  remove_action('wp_head', 'wp_generator');
  remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);

  //Remove Header Stuffs
    // remove junk from head
    remove_action('wp_head', 'index_rel_link');
    remove_action('wp_head', 'feed_links_extra', 3);
    remove_action('wp_head', 'start_post_rel_link', 10, 0);
    remove_action('wp_head', 'parent_post_rel_link', 10, 0);
    remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);

  global $wp_widget_factory;
  remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'));

  add_filter('use_default_gallery_style', '__return_null');
}
add_action('init', 'roots_head_cleanup');

Select Post Parent from Another Post Type in WordPress

add_action('admin_menu', function() {
    remove_meta_box('pageparentdiv', 'chapter', 'normal');
});
add_action('add_meta_boxes', function() {
    add_meta_box('chapter-parent', 'Part', 'chapter_attributes_meta_box', 'chapter', 'side', 'high');
});

function chapter_attributes_meta_box($post) {
    $post_type_object = get_post_type_object($post->post_type);
    if ( $post_type_object->hierarchical ) {
        $pages = wp_dropdown_pages(array('post_type' => 'part', 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('(no parent)'), 'sort_column'=> 'menu_order, post_title', 'echo' => 0));
        if ( ! empty($pages) ) {
            echo $pages;
        } // end empty pages check
    } // end hierarchical check.
}

Create Custom Post Type Template

function codex_custom_init() {
  $labels = array(
    'name' => 'Books',
    'singular_name' => 'Book',
    'add_new' => 'Add New',
    'add_new_item' => 'Add New Book',
    'edit_item' => 'Edit Book',
    'new_item' => 'New Book',
    'all_items' => 'All Books',
    'view_item' => 'View Book',
    'search_items' => 'Search Books',
    'not_found' =>  'No books found',
    'not_found_in_trash' => 'No books found in Trash', 
    'parent_item_colon' => '',
    'menu_name' => 'Books'
  );

  $args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true,
    'rewrite' => array( 'slug' => 'book' ),
    'capability_type' => 'post',
    'has_archive' => true, 
    'hierarchical' => false,
    'menu_position' => null,
    'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
  ); 

  register_post_type( 'book', $args );
}
add_action( 'init', 'codex_custom_init' );

How-to Disable WordPress Auto Updates

If you for some reason do not like that WordPress auto updates some of your stuff, you can use the following few snippets to disable auto-updates for good. While it’s not recommended due to security precautions, some might prefer to work with these on a sandbox environment.

//Disable Theme Updates # 3.0+
remove_action( 'load-update-core.php', 'wp_update_themes' );
add_filter( 'pre_site_transient_update_themes', create_function( '$a', "return null;" ) );
wp_clear_scheduled_hook( 'wp_update_themes' );
Disable Plugin Updates #3.0+

//Disable Plugin Updates #3.0+
remove_action( 'load-update-core.php', 'wp_update_plugins' );
add_filter( 'pre_site_transient_update_plugins', create_function( '$a', "return null;" ) );
wp_clear_scheduled_hook( 'wp_update_plugins' );
Diasable Core Updates # 3.0+

//Diasable Core Updates # 3.0+
add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) );
wp_clear_scheduled_hook( 'wp_version_check' );

You need to put these in the functions.php file.

Image URL Column in Media Manage Dashboard

This also needs to be put in the functions file. Save yourself some time by not having to view each image individually to finds its URL.

function muc_column( $cols ) {
        $cols["media_url"] = "URL";
        return $cols;
}
function muc_value( $column_name, $id ) {
        if ( $column_name == "media_url" ) echo '';
}
add_filter( 'manage_media_columns', 'muc_column' );
add_action( 'manage_media_custom_column', 'muc_value', 10, 2 );

WordPress Tricks & Tips to Help You Manage Your Blog

I’ve hand picked these, and most of them provide some form of time saving functionality, which is the thing that I’m always striving for. If you’d like more/deeper explanation on any of these tricks and tips, please leave a comment and I’ll do my best to elaborate.