HTTP Error FixCan now upload large images

When uploading large images over an approximate size (~2500×2000) I was encountering the HTTP Error message when trying to crunch the image (which ultimately fails and doesn’t produce the smaller pre-defined image sizes).

After trying several solutions, the following appears to have solved it for my setup, once and for all – add this to your .htaccess file:

View the code

Style Sheet Header ImprovementsTidy up your WordPress Theme Details

The Theme Review Guidelines are often updated as each new version of WordPress is released, and although these guidelines are for themes submitted to the WordPress theme repository, they are a good baseline to which all themes should strive to achieve.

If your theme was written a while ago, your site might not be following all of the current best practices. Here are a few simple alterations you can make to your style.css file.

View the suggested improvements

Install WordPress via SSH

  1. SSH into your server, then navigate to your domain’s web root:
    cd /var/www/vhosts/example.com/httpdocs
  2. Grab the latest WP install
    wget http://wordpress.org/latest.tar.gz
  3. Get the files out of the archive:
    tar xfz latest.tar.gz
  4. Navigate to the wordpress subfolder:
    cd wordpress
  5. Copy everything back up to the web root:
    cp -rpf * ../
  6. Navigate back up to web root:
    cd ..
  7. Remove the wordpress subfolder:
    rm -rf wordpress
  8. Remove the downloaded archive file:
    rm -f latest.tar.gz

How to Conditionally Add Style Sheets for IE in WordPress

Over time, Internet Explorer (IE) is getting better at rendering web pages how we want them, but while IE7 and earlier versions still have a (fast-fading) grip, we sometimes still need to provide exclusive styles to make them render our sites in an acceptable way. That is where conditional style sheets are used.
View the code

How to Correctly Add a Tweet Button

The end result from a different Genesis article on How to Add a Tweet Button on Single Posts can also be implemented in an advanced way across all themes, which avoids the need to use invalid markup as suggested by Twitter.

Open up the functions.php file in your child theme and add the following code. The code should be entered at the end of the file, just before the closing ?> if there is one.

add_action( 'wp_print_scripts', 'child_add_tweet_button' );
/**
 * Add tweet link and script.
 *
 * @author Gary Jones
 * @link http://code.garyjones.co.uk/add-tweet-button/
 */
function child_add_tweet_button() {

	// Only add this to anything not a page
	if ( ! is_page() ) {

		// Add a script to the bottom of the source
		wp_enqueue_script( 'tweet-button', 'http://platform.twitter.com/widgets.js', array(), '', true );

		// Filter in the required Twitter link for limited and unlimited content
		add_filter( 'the_content', 'child_add_tweet_button_link' );
		add_filter( 'the_content_limit', 'child_add_tweet_button_link' );

		// Remove stripped link from excerpts.
		add_filter( 'wp_trim_excerpt', 'child_remove_stripped_tweet_button' );

		// Optionally add it in to excerpts properly (uncomment to use).
		//add_filter( 'the_excerpt', 'child_add_tweet_button_link' );
	}
}

/**
 * Add tweet link.
 *
 * @author Gary Jones
 * @link http://code.garyjones.co.uk/add-tweet-button/
 *
 * @param string $content HTML markup for post content
 * @return string HTML markup for post content
 */
function child_add_tweet_button_link( $content ) {
	global $post;

	$query_string_parameters = array(

		// URL of the page to share
		'url' => get_permalink(),

		// Screen name of the user to attribute the Tweet to
		'via' => 'GaryJ',

		// Default Tweet text - here, the post title
		'text' => get_the_title( $post->ID ),

		// Related accounts that will be suggested to follow once tweet has been shared
		'related' => '',

		// Count box position - 'horizontal', 'vertical' or 'none'
		'count' => 'vertical',

		// The language for the Tweet Button - default is English (en)
		'lang' => 'en',

		// The URL to which your shared URL resolves to
		'counturl' => get_permalink()
	);

	// Optionally use this if you have custom shortlinks set up. Uncomment to use.
	//$query_string_parameters['url'] = wp_get_shortlink();

	// Construct our URL to pass to Twitter - gets urlencoded here
	$twitter_url = add_query_arg( $query_string_parameters, '//twitter.com/share' );

	return '<a href="' . htmlspecialchars( $twitter_url ) . '" class="twitter-share-button">Tweet</a>' . $content;
}

/**
 * Excerpt strip HTML, so the Tweet link just ends up as "Tweet" prefixed to the first word of the excerpt.
 *
 * Does mean that you can't start any article with the word Tweet, but this is an edge scenario.
 *
 * @author Gary Jones
 * @link http://code.garyjones.co.uk/add-tweet-button/
 *
 * @param string $content Plain text
 * @return string
 */
function child_remove_stripped_tweet_button( $content ) {
	return preg_replace( '/^Tweet/', '', $content, 1 );
}

While being substantially more code, this has several advantages:

  • If JavaScript isn’t enabled, the markup is still valid for the default Genesis doctype; data-* attributes are only valid in HTML5, and while most users will have this switched out of the DOM in favour of the added iframe, the markup added by the first method is invalid for XHTML 1.0 Strict.
  • The JavaScript from Twitter is only added once, at the bottom of the page, and not every time the button appears, such as on archive pages.
  • The “text” argument is explicitely given as the title of the post in which the button appears (and not the title of the page where the post appears), meaning you can add buttons to posts on archive pages, or featured posts widget posts, and have the correct text be used.
  • You can easily and optionally enable the button for excerpts as well as limited and unlimited post content.
  • You can easily and optionally have your post shortlink as the URL to share, instead of the full permalink. Good if you’re tracking traffic through the shortlink.
  • There are no redundant “Tweet” strings added at the beginning of excerpts, where the markup has been stripped.
  • There is support for the “related” and “lang” arguments, allowing easier customization.