• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Genesis Snippets

A reference for Genesis theme developers

  • Home
  • Archives
  • Search Genesis Snippets

Override CSS cache – Force CSS changes to go live immediately

March 21, 2012 By David Wang

You can prevent web browsers from caching your CSS files by adding a parameter to the end of the stylesheet URI, e.g. ../themename/style.css?v=123. The following is how to do this in Genesis.

/** CSS Cache Buster */
define( 'CHILD_THEME_VERSION', filemtime( get_stylesheet_directory() . '/style.css' ) );

When Genesis enqueues the child theme’s stylesheet, it checks to see if ‘CHILD_THEME_VERSION’ is defined. If it is, that is used as the version. If it isn’t, the parent theme’s version number is used. The code sets the child theme version to the last modified date of style.css. So when you modify it, the URL to your stylesheet changes and the cache is busted.

Credit: Bill Erickson

———

Update 2014.06.17: The method above declares CHILD_THEME_VERSION a 2nd time which throws a PHP notice in WordPress. If you don’t like that, you can use the following methods instead.

Add filetime parameter to the style.css link

add_filter( 'stylesheet_uri', 'child_stylesheet_uri' );
/**
 * Cache bust the style.css reference.
 *
 */
function child_stylesheet_uri( $stylesheet_uri ) {
    return add_query_arg( 'v', filemtime( get_stylesheet_directory() . '/style.css' ), $stylesheet_uri );
}

Credit: Greg Rickaby

And finally, here’s a method from WP Engineer you can adapt for use in Genesis too: Force Reload of Scripts and Stylesheets in your Plugin or Theme

Filed Under: Genesis Tagged With: cache, css

Define Genesis default options

March 20, 2012 By David Wang

Define preset options for Genesis child themes so that when activated, you don’t need to muck around the Theme Settings page.

/** Define Genesis Options */
add_filter('genesis_options', 'define_genesis_setting_custom', 10, 2);
function define_genesis_setting_custom($options, $setting) {
    if($setting == GENESIS_SETTINGS_FIELD) {
        $options['show_info'] = 0; // Display theme info in document source
        $options['update'] = 1; // Enable Automatic Updates
        $options['update_email'] = 0; // Notify when updates are available
        $options['update_email_address'] = ''; // Update email address
        $options['feed_uri'] = ''; // Custom reed URI
        $options['redirect_feed'] = 0; // Redirect reed
        $options['comments_feed_uri'] = ''; // Custom comments feed URI
        $options['redirect_comments_feed'] = 0; // Redirect feed
        $options['site_layout'] = 'content-sidebar'; // Default layout
        $options['blog_title'] = 'text'; // Blog title/logo - 'text' or 'image'
        $options['nav'] = 1; // Include primary navigation
        $options['nav_superfish'] = 1; // Enable fancy dropdowns
        $options['nav_extras_enable'] = 0; // Enable extras
        $options['nav_extras'] = 'date'; // Extras - 'date', 'rss', 'search', 'twitter'
        $options['nav_extras_twitter_id'] = ''; // Twitter ID
        $options['nav_extras_twitter_text'] = 'Follow me on Twitter'; // Twitter link text
        $options['subnav'] = 0; // Include secondary navigation
        $options['subnav_superfish'] = 1; // Enable fancy dropdowns
        $options['breadcrumb_home'] = 1; // Enable breadcrumbs on Front Page
        $options['breadcrumb_single'] = 1; // Enable breadcrumbs on Posts
        $options['breadcrumb_page'] = 1; // Enable breadcrumbs on Pages
        $options['breadcrumb_archive'] = 1; // Enable breadcrumbs on Archives
        $options['breadcrumb_404'] = 1; // Enable breadcrumbs on 404 Page
        $options['breadcrumb_attachment'] = 1; // Enable breadcrumbs on Attachment Pages
        $options['comments_posts'] = 1; // Enable comments on Posts
        $options['comments_pages'] = 0; // Enable comments on Pages
        $options['trackbacks_posts'] = 1; // Enable trackbacks on Posts
        $options['trackbacks_pages'] = 0; // Enable trackbacks on Pages
        $options['content_archive'] = 'full'; // Content archives display - 'full', 'excerpts'
        $options['content_archive_limit'] = ''; // Limit content to n characters
        $options['content_archive_thumbnail'] = 0; // Include featured image
        $options['posts_nav'] = 'older-newer'; // Post navigation - 'older-newer', 'prev-next', 'numeric'
        $options['blog_cat'] = '0'; // Blog page displays which category
        $options['blog_cat_exclude'] = ''; // Blog page excludes which category 
        $options['blog_cat_num'] = 10; // Number of posts to show
        $options['header_scripts'] = ''; // Header scripts
        $options['footer_scripts'] = ''; // Footer scripts
        }
    return $options;
}

Updated from Christopher Cochran

Filed Under: Genesis Tagged With: theme options

Remove unused page layouts

March 20, 2012 By David Wang

Genesis comes with 6 page layouts, which you may not need for every site. Here’s how to remove them.

/** Remove Unused Page Layouts */
// Un-comment the page layouts you wish to remove
//genesis_unregister_layout( 'full-width-content' );
//genesis_unregister_layout( 'content-sidebar' );	
genesis_unregister_layout( 'sidebar-content' );
genesis_unregister_layout( 'content-sidebar-sidebar' );
genesis_unregister_layout( 'sidebar-sidebar-content' );
genesis_unregister_layout( 'sidebar-content-sidebar' );

Credit: Bill Erickson

Filed Under: Genesis Tagged With: page layouts, theme options

Remove unused theme settings metaboxes

March 20, 2012 By David Wang

Hide the Header, Navigation, Breadcrumb and Blog Page settings in the Genesis Theme Settings page. Uncomment the corresponding lines for the metaboxes you want to remove

/** Remove unused theme settings */
add_action( 'genesis_theme_settings_metaboxes', 'child_remove_metaboxes' );
function child_remove_metaboxes( $_genesis_theme_settings_pagehook ) {
	remove_meta_box( 'genesis-theme-settings-header', $_genesis_theme_settings_pagehook, 'main' );
	remove_meta_box( 'genesis-theme-settings-nav', $_genesis_theme_settings_pagehook, 'main' );
	remove_meta_box( 'genesis-theme-settings-layout', $_genesis_theme_settings_pagehook, 'main' );
	remove_meta_box( 'genesis-theme-settings-breadcrumb', $_genesis_theme_settings_pagehook, 'main' );
//	remove_meta_box( 'genesis-theme-settings-comments', $_genesis_theme_settings_pagehook, 'main' );
//	remove_meta_box( 'genesis-theme-settings-blogpage', $_genesis_theme_settings_pagehook, 'main' );
}

Updated from Bill Erickson

Tip: Use this in conjunction with defining default theme options so that old settings are not stuck with the old values.

Filed Under: Genesis Tagged With: theme options

Force Superfish menus

March 20, 2012 By David Wang

Force the Superfish script to be activated on navigation menus using the genesis_pre_get_option_ filter.

add_filter( 'genesis_pre_get_option_nav_superfish', 'nrp_get_option_nav_superfish' );
function nrp_get_option_nav_superfish( $opt ) {
	$opt = '1';
	return $opt;
}

Tip: Use this in conjunction with removing unused theme settings metaboxes so that users are not confused with why their settings are not being saved.

Filed Under: Genesis Tagged With: menu, navigation, theme options

Force navigation menu display

March 20, 2012 By David Wang

Force the primary menu to be displayed using the genesis_pre_get_option_ filter.

add_filter( 'genesis_pre_get_option_nav', 'child_get_option_nav' );
function child_get_option_nav( $opt ) {
	$opt = '1';
	return $opt;
}

Tip: Use this in conjunction with removing unused theme settings metaboxes so that users are not confused with why their settings are not being saved.

Filed Under: Genesis Tagged With: menu, navigation, theme options

  • « Go to Previous Page
  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to page 4

Primary Sidebar

Brought to you by ClickWP
Buy the Genesis Theme Framework

Who’s behind this?

Hi! I'm David and I'm a big Genesis fan. I've been using it in all my projects and have found it to be super powerful.

I started this site to keep track of all the snippets that I've been using in my projects and so that it's easy for me to find them again instead of digging through my old project files.

Help support this site by buying Genesis with our affiliate links. Thanks!

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 354 other subscribers

Browse Snippets

branding cache comments css custom post type doctype entry footer entry header favicon featured image genesis_custom_loop images internet explorer jetpack loop media menu metabox minify navigation oembed page layouts performance plugin integration post thumbnail shortcode sidebars theme options widget areas widgets WooCommerce WordPress
Everything you need to support your online business
Take WordPress further with the Genesis framework

Copyright © 2025 · Genesis Sample On Genesis Framework · WordPress · Log in