How to remove deprecated widgets from the Genesis Framework

The latest version of Genesis has deprecated two widgets, but they still annoyingly show up in the widgets panel even if you’re not using them. Thankfully it’s easy to remove them using WordPress’s unregister_widget function. Just place the following code in your functions.php:

add_action ('widgets_init', 'emw_remove_deprecated_widgets', 15);

function emw_remove_deprecated_widgets() {
	unregister_widget ('Genesis_Widget_Menu_Categories');
	unregister_widget ('Genesis_Menu_Pages_Widget');
}

How to add excerpt support for WordPress pages

Adding a custom excerpt in WordPress posts is easy – when you’re editing a post, you can turn on the excerpt metabox in screen options and away you go. But that option is not available when you’re editing pages. Thankfully, the add_post_type_support function makes it very easy to add.

add_action ('init', 'emw_add_excerpt_support');

function emw_add_excerpt_support () {
	add_post_type_support('page', 'excerpt');
}

Or, if you want it in one line:

add_action ('init', create_function ('', "add_post_type_support('page', 'excerpt');"));

How to make sure your custom CSS is cached by the browser

If you’re writing a custom theme, you’ll want to make sure that the browser properly caches the CSS, so that it’s not requested each time. To solve this, you add a cache-control header to your .htaccess file:

<filesMatch "\.(css)$">
Header set Cache-Control "max-age=290304000, public"
</filesMatch>

But what if you subsequently change the CSS? If you’re not careful, users who have previously visited your site will still be using the old, cached file. The easy way to solve this is to use PHP’s filemtime to provide a version number to the wp_register_style function. This version number will be appended as a query parameter to your CSS request. When it changes, it will force the browser to re-request the file. The code goes something like this:

$timestamp = @filemtime(get_stylesheet_directory().'/style.css');
wp_register_style ('custom-style', get_stylesheet_directory_uri().'/style.css', array(), $timestamp);

If you’re not able to edit .htaccess to add the necessary headers, there is a simple solution. Rename style.css to style.php (and do the same in the code above). Now add the following lines to the top of the style.php file:

<?php
header ('Cache-Control: max-age=290304000, public');
header ('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time()+290304000));
header ('Content-type: text/css');
$date = @filemtime(__FILE__);
if ($date)
	header ('Last-Modified: '.gmdate('D, d M Y H:i:s \G\M\T', $date));
?>