WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Jan 07 2013

Create Genesis Constants Based on Theme

In my child themes, this little function that I wrote based on the new wp_get_theme() function (Codex, WP Ticket). Previously, I had to create style.css with all the data and then had to do the same thing in functions.php (or my child init.php). So to save 30 seconds or so, I have no fully automated this entirely, so everything in style.css matters. Everything!

Let's step through the style.css header.

/*
Theme Name: Genesis Child
Theme URI: http://wpsmith.net/
Description: Default Genesis Child Theme.
Author: Travis Smith
Author URI: http://wpsmith.net/
Version: 1.0.0
Text Domain: genesis-child
Tags: black, white, red, one-column, two-columns, three-columns, left-sidebar, right-sidebar, fixed-width, custom-background, custom-header, custom-menu, editor-style, full-width-template, sticky-post, theme-options, threaded-comments, translation-ready
Template: genesis
Template Version: 1.9.0
License: GNU General Public License v3.0 (or later)
License URI: http://opensource.org/licenses/gpl-license.php
*/
view raw style.css hosted with ❤ by GitHub

Obviously, Template and Template version should be set for every child theme.

So Theme Name will determine CHILD_THEME_NAME, which will automatically appear in the Genesis Footer connected with the Theme URI, which is set as CHILD_THEME_URL. WordPress pulls in the Description on the Appearance > Themes page. I have an admin script that I make better use of Author and Author URI besides the basic WordPress listing them in Appearance > Themes (as it also uses Tags). It places it in the footer stating, "Thank you for creating with WordPress & CHILD_THEME_NAME designed by CHILD_DEVELOPER" linked with CHILD_DEVELOPER_URL.

What's even more awesome is that Genesis 1.9 makes use of CHILD_THEME_VERSION if it is set in enqueuing the style. So, it's important, but I also use it elsewhere. Then the even more awesome thing is Text Domain! Text Domain sets two constants: CHILD_DOMAIN (localization) and CHILD_THEME_SETTINGS (admin page). So if Text Domain is set as 'genesis-child' then the CHILD_DOMAIN will be 'genesis-child' and the CHILD_THEME_SETTINGS will be 'genesis-child-settings'.

Now, I don't have to think a single bit for my theme constants. I just use this function in all child themes I create.

<?php
add_action( 'genesis_init', 'gs_constants', 15 );
/**
* This function defines the Genesis Child theme constants
*
* Data Constants: CHILD_SETTINGS_FIELD, CHILD_DOMAIN, CHILD_THEME_VERSION
* CHILD_THEME_NAME, CHILD_THEME_URL, CHILD_DEVELOPER, CHILD_DEVELOPER_URL
* Directories: CHILD_LIB_DIR, CHILD_IMAGES_DIR, CHILD_ADMIN_DIR, CHILD_JS_DIR, CHILD_CSS_DIR
* URLs: CHILD_LIB, CHILD_IMAGES, CHILD_ADMIN, CHILD_JS, CHILD_CSS
*
* @since 1.1.0
*/
function gs_constants() {
$theme = wp_get_theme();
// Child theme (Change but do not remove)
/** @type constant Child Theme Options/Settings. */
define( 'CHILD_SETTINGS_FIELD', $theme->get('TextDomain') . '-settings' );
/** @type constant Text Domain. */
define( 'CHILD_DOMAIN', $theme->get('TextDomain') );
/** @type constant Child Theme Version. */
define( 'CHILD_THEME_VERSION', $theme->Version );
/** @type constant Child Theme Name, used in footer. */
define( 'CHILD_THEME_NAME', $theme->Name );
/** @type constant Child Theme URL, used in footer. */
define( 'CHILD_THEME_URL', $theme->get('ThemeURI') );
// Developer Information, see lib/admin/admin-functions.php
/** @type constant Child Theme Developer, used in footer. */
define( 'CHILD_DEVELOPER', $theme->Author );
/** @type constant Child Theme Developer URL, used in footer. */
define( 'CHILD_DEVELOPER_URL', $theme->{'Author URI'} );
// Define Directory Location Constants
/** @type constant Child Theme Library/Includes URL Location. */
define( 'CHILD_LIB_DIR', CHILD_DIR . '/lib' );
/** @type constant Child Theme Images URL Location. */
define( 'CHILD_IMAGES_DIR', CHILD_DIR . '/images' );
/** @type constant Child Theme Admin URL Location. */
define( 'CHILD_ADMIN_DIR', CHILD_LIB_DIR . '/admin' );
/** @type constant Child Theme JS URL Location. */
define( 'CHILD_JS_DIR', CHILD_DIR .'/js' );
/** @type constant Child Theme JS URL Location. */
define( 'CHILD_CSS_DIR', CHILD_DIR .'/css' );
// Define URL Location Constants
/** @type constant Child Theme Library/Includes URL Location. */
define( 'CHILD_LIB', CHILD_URL . '/lib' );
/** @type constant Child Theme Images URL Location. */
define( 'CHILD_IMAGES', CHILD_URL . '/images' );
/** @type constant Child Theme Admin URL Location. */
define( 'CHILD_ADMIN', CHILD_LIB . '/admin' );
/** @type constant Child Theme JS URL Location. */
define( 'CHILD_JS', CHILD_URL .'/js' );
/** @type constant Child Theme JS URL Location. */
define( 'CHILD_CSS', CHILD_URL .'/css' );
}
view raw gs_constants.php hosted with ❤ by GitHub

Written by Travis Smith · Categorized: WordPress

Jan 04 2013

Add private/draft/future/pending pages to parent dropdown in page attributes and Quick Edit

<?php
add_filter( 'page_attributes_dropdown_pages_args', 'wps_dropdown_pages_args_add_parents' );
add_filter( 'quick_edit_dropdown_pages_args', 'wps_dropdown_pages_args_add_parents' );
/**
* Add private/draft/future/pending pages to parent dropdown.
*/
function wps_dropdown_pages_args_add_parents( $dropdown_args, $post = NULL ) {
$dropdown_args['post_status'] = array( 'publish', 'draft', 'pending', 'future', 'private', );
return $dropdown_args;
}
view raw wps_dropdown_pages_args_add_parents.php hosted with ❤ by GitHub

Written by Travis Smith · Categorized: WordPress

Jan 03 2013

Disable AutoSave on Add New Post Admin Page

Disabling revisions won't stop WordPress from creating the initial draft version of a custom post type. So I used this snippet to accomplish this as well.

<?php
add_action( 'admin_enqueue_scripts', 'wps_cpt_admin_enqueue_scripts' );
/**
* Disable initial autosave/autodraft
*/
function wps_cpt_admin_enqueue_scripts() {
if ( 'cpt' == get_post_type() )
wp_dequeue_script( 'autosave' );
}
view raw wps_cpt_admin_enqueue_scripts.php hosted with ❤ by GitHub

Written by Travis Smith · Categorized: Custom Post Types

Dec 28 2012

Genesis Child Theme Code Audit

Calling all Genesis developers! Through January 2nd, I am offering a basic initial audit of up to 4 Genesis child themes for $50 and only $50!

Get it Now!

You may be thinking, "Why should I audit my theme if it is selling already so well?" Or, "My theme is on the Genesis Marketplace and doesn't need to be audited." Or, "I purchased this from the Genesis Marketplace, so the theme has already been audited." Or, "I developed this theme for a client who won't know." Or, "I had this theme developed by another Genesis developer, and I am just not sure about it."

First, themes on the Genesis Marketplace have not necessarily been audited. Genesis Marketplace themes are developer dependent. While StudioPress recommended these themes be audited by myself or Gary Jones or another developer, the submitting developer may or may not have done this because until now, audits were expensive. Thus, the theme may or may not be written to WordPress standards and/or best practices.

Second, themes audited almost always reveal something, which will lead to easier maintenance, lower support costs, code confidence, and happier customers! Customers always find out how good or bad the code is/was that was written. The theme/site may come into conflict with a plugin that they want to use. The theme/site may have issues with the Genesis/WordPress upgrade cycle. Whatever the case, they either return to you, try to do it themselves, or hire another Genesis developer. Even themes/sites I've built six months ago give me shivers when I go back and work on them. I've worked on themes that were originally developed by many Genesis developers and surely there have been Genesis developers who have worked on sites that I originally created. If, however, I had the theme/site audited then I would have most definitely produced a better product and had more confidence in my code.

Get the Audit Today

Written by Travis Smith · Categorized: Genesis

Nov 18 2012

Dequeue Soliloquy Style

Since Soliloquy does not "properly" enqueue the flexslider stylesheet (only meaning, it doesn't hook into wp_enqueue_scripts, and frankly, it does it with the best approach IMHO). Here is the proper hook to remove the default Soliloquy style sheet.

Written by Travis Smith · Categorized: Plugins

  • « Previous Page
  • 1
  • …
  • 11
  • 12
  • 13
  • 14
  • 15
  • …
  • 61
  • Next Page »
  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in