How to randomize the order of widgets

Sometimes you might want to display a sidebar with the widgets in a random order. It’s very simple:

add_filter ('sidebars_widgets', 'wcs_randomize_widget_order');

function wcs_randomize_widget_order($sidebars_widgets) {
    $sidebar = 'sidebar'; // Replace 'sidebar' with the name of the widget you want to shuffle
    if (isset($sidebars_widgets[$sidebar]) && !is_admin()) {
        shuffle ($sidebars_widgets[$sidebar]);
    }
    return $sidebars_widgets;
}

If you want to randomize the widgets in all your sidebars, you can use a foreach loop.

How to stop Chrome using a large font size after refreshing

I was having a torrid time trying to work out why sometimes my Genesis site had a much bigger font that it should have done. It only occurred in Chrome, and even more bizarrely, it was often OK the first time you viewed a a page, but only occurred when you refreshed it!

It turns out to be a chrome bug, and the work around is very simple, as described in this stackoverflow question. It’s caused because Genesis child themes tend to use the rem unit of measurements on the body tag. The rem unit is supposed to stop font-sizes compounding and getting out of control, but for some reason Chrome trips over when there’s an rem unit on the body tag. The good news is that you don’t need a rem unit on the body tag, because ems are only a problem when you have lots of them. Having one em unit is fine.

So if you’re affected by this bug, just look for the body tag in your CSS file, and change the font-size unit from rem to em – like this:

From this:

body {
	color: #666;
	font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
	font-size: 16px;
	font-size: 1.6rem;
	font-weight: 300;
	line-height: 1.625;
}

To this:

body {
	color: #666;
	font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
	font-size: 16px;
	font-size: 1.6em;
	font-weight: 300;
	line-height: 1.625;
}

Prevent WordPress from deleting a post

At first glance it seems as though there are no hooks or filters in WordPress for preventing a post/page deletion. But you can do it by filtering user_has_cap (short for user has capability). This is a very powerful filter, and you can use it to … [Continue reading]

Using the non-minified version of jQuery in WordPress

If you're developing in WordPress, you'll probably have define('SCRIPT_DEBUG', true); in your wp-config.php file, which ensures that WordPress does not load minified javascript files. Unfortunately, because of it's large size a non-minified version … [Continue reading]

How to make sure the correct domain is used in WPML

If you use the WPML multilingual plugin for WordPress, and have each language on a different domain, you may have noticed that WPML does not ensure that all URLs in your page point to the correct domain. You might notice, for example, that images are … [Continue reading]

Adding a favicon to your site (including at the root)

Adding a favicon is an important finishing touch to building your site. If your theme doesn't support favicons, you can add a favicon by adding the following code to your functions.php : If your theme already supports favicons, chances are … [Continue reading]

Don’t edit child themes – use grandchild themes!

Child themes are the easiest way to style WordPress sites. Rather than create a site from scratch, you can create a theme that shares most of its code and styling with a parent theme. The benefits of creating a child theme instead of editing the main … [Continue reading]

Synchronize a menu with your page hierarchy

WordPress's menu feature is a fantastic way of creating a hierarchical menu, but unfortunately you still have to keep your pages in their own, separate hierarchy, using a horribly cumbersome interface, or a special plugin. The code snippet below will … [Continue reading]

Automatically add Lorem Ipsum text to blank WordPress pages

If you're creating a new Wordpress theme, it can be helpful to have some filler text in your pages. The snippet below adds a few paragraphs of lorem ipsum text to any blank post or page by filtering the_content. The text is retrieved from the … [Continue reading]

Changing the settings for Genesis Reponsive Slider to allow multiple slideshows

Out of the box, the Genesis Responsive Slider can only be used in one way on your site because it's options are set in an options panel. However, you can hook in to every setting, to create different sliders on different pages (although this code … [Continue reading]