Below are best practices for functions when coding for the Genesis Framework:
1. Include theme name as the prefix of a function name.
The right way to do it:
/** Add Viewport meta tag for mobile browsers */
add_action( 'genesis_meta', 'freelance_add_viewport_meta_tag' );
function freelance_add_viewport_meta_tag() {
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0"/>';
}
The wrong way to do it:
/** Add Viewport meta tag for mobile browsers */
add_action( 'genesis_meta', 'add_viewport_meta_tag' );
function add_viewport_meta_tag() {
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0"/>';
}
2. Include a space before and after paramaters of filter and functions.
The right way to do it:
/** Add support for custom header */
add_theme_support( 'genesis-custom-header', array( 'width' => 960, 'height' => 100 ) );
The wrong way to do it:
/** Add support for custom header */
add_theme_support('genesis-custom-header', array( 'width' => 960, 'height' => 100 ));
3. Use lowercase, hyphenated instances of registering image sizes with multiple words.
The right way to do it:
/** Add new image sizes */
add_image_size( 'homepage', 600, 200, TRUE );
add_image_size( 'home-featured', 250, 200, TRUE );
add_image_size( 'home-bottom-left', 125, 125, TRUE );
The wrong way to do it:
/** Add new image sizes */
add_image_size( 'Homepage', 600, 200, TRUE );
add_image_size( 'Home Featured', 250, 200, TRUE );
add_image_size( 'Home Bottom Left', 125, 125, TRUE );