Tag Archives: WordPress

Laying out a grid in WordPress

For a recent project, I needed to lay items out in a series of grids, sometimes three columns, sometimes more. The CSS provided by the designer looked something like this:

.columns section {
float: left;
margin-left: 20px;
width: 220px;
}
.columns section.one {
clear: left;
margin-left: 0;
}

I could have used jQuery, or some of the more advanced CSS selectors, to achieve this, but here’s what I created as a custom WordPress template tag. Continue reading

Gravity forms access for editors

Gravity Forms is an excellent WordPress plugin, which allows flexible and easy control and creation of pretty much any kind of form in your website. Behind the scenes it has a very flexible integration with the WordPress system of roles and capabilities, which governs who can do what in your admin area. Continue reading

Excluding one category from the main WordPress feed

Today I needed to exclude a category from the main WordPress posts feed, the one you’ll find at http://mywordpresssite.com/feed/; however I didn’t want to exclude posts in that category from other feeds (especially not from that category’s feed at http://mywordpresssite.com/excluded-category/feed/). Here’s how I set about it… Continue reading

WP Super Cache and WP Touch (Pro)

On one client’s site we’re using WP Super Cache and WP Touch Pro, and it bothered me that while WP Touch Pro ensures that mobile users get a lovely optimised theme, it wasn’t serving cached pages for those queries. Until recently we were hacking both WP Super Cache and WP Touch (pre-Pro) to achieve this, but recent changes in both plugins mean we can avoid the egregious charge of tampering with other people’s plugin code.

Three fairly simple steps: Continue reading

Scaling WordPress & Co-ordinating Code at WordUp Whitehall

Thanks to Simon Dickson for inviting me to speak at WordUp Whitehall, a specialist and informal one day WordPress conference for people working in UK Government. I don’t do enough speaking, something I need to address, and this was a great opportunity to share some of the knowledge gained from working on relaunching the recent Defra project.

My presentation covered two quite separate topics: scaling WordPress for large amounts of traffic, and how version control can be useful for client in-house teams.

Here’s a PDF version of the talk, and certainly let me know if there’s any speaking opportunities coming up… I’m available! Scaling WordPress & Co-ordinating code

There’s a lot of images used in the presentation, and thanks to the following for providing their photos under a Creative Commons license:

© @hwayoungjung – http://www.flickr.com/photos/hwayoungjung/3742229597/
© Andrew Becraft – http://www.flickr.com/photos/dunechaser/2816064611/
© Christian Payne –http://www.flickr.com/photos/christianpayne/3524859632/in/photostream/
© Don Solo – http://www.flickr.com/photos/donsolo/2886355241/
© Evan Moss – http://www.flickr.com/photos/mightymoss/4163027317/in/photostream/
© Federico Casares – http://www.flickr.com/photos/solofotones/1839531915/
© Garrett & Kitty Wilkin –http://www.flickr.com/photos/gareandkitty/338059022/in/photostream/
© Garrett Coakley – http://www.flickr.com/photos/garrettc/2172850095/
© Gopal Vijayaraghavan –http://www.flickr.com/photos/t3rmin4t0r/3947963283/in/photostream/
© H.Powers – http://www.flickr.com/photos/melisande-origami/108813447/sizes/l/
© H.Powers – http://www.flickr.com/photos/melisande-origami/108813447/sizes/l/
© Hobvias Sudoneighm – http://www.flickr.com/photos/striatic/3834431/
© Jimmie –http://www.flickr.com/photos/jimmiehomeschoolmom/2810673350/in/photostream/
© Joseph Robertson – http://www.flickr.com/photos/josephrobertson/59407804/
© Mike McCune – http://www.flickr.com/photos/mccun934/3261249676/
© Mo Riza – http://www.flickr.com/photos/moriza/96724309/in/photostream/
© Mo Riza – http://www.flickr.com/photos/moriza/96724309/in/photostream/
© Pyno Moscato – http://www.flickr.com/photos/pinomoscato/3992211669/
© Rob Shenk – http://www.flickr.com/photos/rcsj/400758302/sizes/l/in/photostream/
© Sean Dreilinger –http://www.flickr.com/photos/seandreilinger/2326448445/in/photostream/
© Sean Dreilinger –http://www.flickr.com/photos/seandreilinger/2326448445/in/photostream/
© Steve Harwood – http://www.flickr.com/photos/captkodak/272746539/in/photostream/
© Thomas Hawk – http://www.flickr.com/photos/thomashawk/2442371176/
© Troy Holden – http://www.flickr.com/photos/troyholden/4114564467/in/photostream/

Including data in the page for your plugin’s JavaScript

Nip over to Otto’s blog and read his post entitled don’t include wp-load, please which I’m in complete and total agreement with. I’d like to add to the solutions with the following method of adding data to your page for use by your plugin’s JavaScript: wp_localize_script. Continue reading

Taking stock

I have a client with a lot lot lot lot of WordPress sites, and I’m helping them craft a strategy for dealing with WordPress throughout their business. One thing we wanted to do was to take stock of all the plugins they have installed on all their sites, work out how many are in common, understand if any have security issues and so forth. Logging into hundreds of WordPress sites, even if we did have their login details, isn’t my idea of fun so I hacked some of the WordPress plugin functions to output a report on any plugins it finds in a directory. Continue reading

Eeek! The load-page-new.php and load-page.php actions have vanished!

So WordPress 3.0 is out, and some of the useful admin area load-* hooks that I use have vanished or changed. To refresh your memory, there are individual and specific hooks which run whenever WordPress loads an admin page. These hooks are named after the PHP file in the URL to the admin page, for example the URL to create a new post is post-new.php so the action you can hook when this page is loaded is “load-post-new.php“. All good. Very handy.

In WordPress 3.0 the URLs to create a post and edit a post are now all post-new.php and post.php, with the post type being passed in a GET parameter like so: post-new.php?post_type=page… i.e. load-page-new.php and load-page.php action hooks have both vanished! Never fear, there are two ways around this problem, read on… Continue reading

Live text streams for the National Care Service

We were approached by the Department of Health to further enhance their WordPress based website for the launch of the National Care Service. The launch was to have a live web video stream and The Department of Health wanted live text updates to accompany the video. The text updates would allow late comers to catch up, mean the launch team could provide annotations, links and accompanying materials as the launch progressed, and would provide a text record of the event afterwards. The projected maximum audience for this event reached well into the thousands, so the solution we provided would have to scale appropriately, while not consuming so many resources that the webserver could not fulfil it’s other duties (like serving other pages and so forth).

Continue reading

Thickboxing in WordPress themes

The lovely Thickbox jQuery plugin appears to no longer be supported by it’s creator, Cody Lindley, but it’s included with WordPress (it provides the “popup” overlays in the post editor for uploading and inserting images and other media), very flexible and that’s good enough reason for me to use it for the time being.

I’ve always been a bit shy of using Thickbox in the front end of WP sites, as the close button and loading animation paths are hard-coded relative to the WP admin area… in short, they don’t work at the front without tinkering. Today I realised that the required tinkering was (relatively) trivial, so here’s my code for including thickbox at the front end, you can drop it into the functions.php of your theme or make it into a plugin.

function my_load_thickbox() {
	add_thickbox();
	?>
	<script type="text/javascript">
		/* <![CDATA[ */
		var tb_pathToImage = '<?php echo esc_js( includes_url( '/js/thickbox/loadingAnimation.gif' ) ); ?>';
		var tb_closeImage = '<?php echo esc_js( includes_url( '/js/thickbox/tb-close.png' ) ); ?>'; 
		/* ]]> */
	</script>
	<?php
}
add_action( 'wp_head', 'my_load_thickbox', 0 );

Taking this section by section:

The add_thickbox function is a wrapper for adding the styling and script for Thickbox; the style gets added to the HTML HEAD element, and the script is added to the footer.

The script block is where the Thickbox image paths are corrected, the technique works because the WP Thickbox script checks if these two paths are set a JS vars before it sets them and uses any pre-existing values. Because the vars in the function above are set before the Thickbox script is loaded (the script has been added to the footer, remember) we are able to override and set some paths which will work on the front end of a WP site. The include_urls function is a handy way to reference some code inside the wp_includes directory (which the two Thickbox images are). The esc_js escapes text for a JS context, it’s included to prevent something hairy and completely unexpected getting into the JS and making a security mess everywhere (it’s always a good idea to escape anywhere and everywhere you can).

(One gotcha: because the scripts are added to the footer, your theme must include a wp_footer action.)