WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Jan 26 2012

Speaking at WordCamp Atlanta

Speaking at WordCamp AtlantaSo, I have been rather lazy announcing this, but I am speaking at WordCamp Atlanta coming up on February 4th at 11am on Professional Rapid Web Development Using the Genesis Framework.

During this seminar I plan to do the following:

  1. Introduce Genesis 1.8 and the new built-in Genesis Admin Class
  2. Introduce/Discuss 3 Other Classes including an Admin Builder Class (by Nick Croft), the Custom Metabox Class (by Jared Atchinson, Bill Erickson, & Andrew Norcross), and the Plugin Activation Class (by Thomas Griffin and Gary Jones) for rapid development
  3. Introduce my Genesis Starter Theme, WPS Starter Flex, which includes nearly everything a Genesis developer will need
  4. Discuss the Core Functionality Plugin approach to building websites
  5. Discuss the various resources available to a Genesis developer including the very active community

Beyond all these things, StudioPress has graciously donated some WordPress swag to give away during the presentation including 1 ProPlus Package & 3 Theme Packages (e.g., AgentPress).

Did I miss anything? Is there anything else that I should include? Please let me know!! I'll see you there!

Written by Travis Smith · Categorized: Genesis, WordPress

Jan 24 2012

How to Add a Custom Screen Icon for Genesis Admin Pages

In a previous post I discussed how to create a child theme admin page, and talked about a few of the new features of Genesis 1.8, . However, one thing I didn't discuss in the creation of the new admin pages is setting a custom screen icon.

While this may or may not make Genesis core, it is a simple addition. So in your __construct() method with $page_ops, enter a screen icon of 'custom'.
[php highlight="22,23,24"]
/**
* Create an admin menu item and settings page.
*
* @since 1.0.0
*/
function __construct() {

// Specify a unique page ID.
$page_id = 'child';

// Set it as a child to genesis, and define the menu and page titles
$menu_ops = array(
'submenu' => array(
'parent_slug' => 'genesis',
'page_title' => 'Genesis - WPS Starter Settings',
'menu_title' => 'WPS Starter Settings',
'capability' => 'manage_options',
)
);

// Set up page options. These are optional, so only uncomment if you want to change the defaults
$page_ops = array(
'screen_icon' => 'custom', // see $this->screen_icon() below
);

// Give it a unique settings field.
// You'll access them from genesis_get_option( 'option_name', CHILD_SETTINGS_FIELD );
$settings_field = CHILD_SETTINGS_FIELD;

// Set the default values
$default_settings = array(
'phone' => '',
'address' => '',
);

// Create the Admin Page
$this->create( $page_id, $menu_ops, $page_ops, $settings_field, $default_settings );

// Initialize the Sanitization Filter
add_action( 'genesis_settings_sanitizer_init', array( $this, 'sanitization_filters' ) );
}
[/php]

Next you will need a method to output the necessary CSS to display your icon.
[php highlight="42,43"]
/**
* Create an admin menu item and settings page.
*
* @since 1.0.0
*/
function __construct() {

// Specify a unique page ID.
$page_id = 'child';

// Set it as a child to genesis, and define the menu and page titles
$menu_ops = array(
'submenu' => array(
'parent_slug' => 'genesis',
'page_title' => 'Genesis - WPS Starter Settings',
'menu_title' => 'WPS Starter Settings',
'capability' => 'manage_options',
)
);

// Set up page options. These are optional, so only uncomment if you want to change the defaults
$page_ops = array(
'screen_icon' => 'custom', // see $this->screen_icon() below
);

// Give it a unique settings field.
// You'll access them from genesis_get_option( 'option_name', CHILD_SETTINGS_FIELD );
$settings_field = CHILD_SETTINGS_FIELD;

// Set the default values
$default_settings = array(
'phone' => '',
'address' => '',
);

// Create the Admin Page
$this->create( $page_id, $menu_ops, $page_ops, $settings_field, $default_settings );

// Initialize the Sanitization Filter
add_action( 'genesis_settings_sanitizer_init', array( $this, 'sanitization_filters' ) );

// Add custom screen icon
add_action( 'admin_head' , array( $this, 'screen_icon' ) );
}
[/php]

Now you will need to create the method within the class extension.
[php]

/**
* Custom Admin screen icon
*
* See /lib/classes/sanitization.php for all available filters.
*
* @since 1.0.0
*/
public function screen_icon() { ?>
<style>
#icon-custom { background-image: url('<?php echo WPS_ADMIN_IMAGES . '/staff_32x32.png'; ?>'); background-repeat: no-repeat; }
</style>
<?php
}
[/php]

Written by Travis Smith · Categorized: WordPress

Jan 23 2012

How to Add an Avatar To WordPress Defaults, Remove Default Avatars, & Set Your Default

With WordPress and Genesis, Avatars are used as identification (like the Twitter icon), and with Gravatar it is in the comment area and the User Profile Widget.

Default Avatars
Click for larger image

WordPress allows the user to set a default or generated Avatar, if the commentator doesn't have one. However, I find these options rather ugly or not fitting to the theme most of the time.

Add an Avatar to WordPress Defaults

So I'd like to show you how to add an avatar to the WordPress defaults.
[php]
// Add Custom Avatar (Discussion Settings)
add_filter( 'avatar_defaults' , 'wps_new_avatar' );
function wps_new_avatar( $avatar_defaults ){
$new_avatar = get_stylesheet_directory_uri() . '/images/genesis-48x48.png';
$avatar_defaults[$new_avatar] = "Genesis";

return $avatar_defaults;
}
[/php]

Add New Avatar
Click for larger image

Remove Default Avatars from WordPress Defaults

For those of us who don't care for some of the WordPress defaults, within that function you can easily remove them at your will:
[php]
// Add Custom Avatar (Discussion Settings)
add_filter( 'avatar_defaults' , 'wps_new_avatar' );
function wps_new_avatar( $avatar_defaults ){
// Get Avatar from child theme images folder
$new_avatar = get_stylesheet_directory_uri() . '/images/genesis-48x48.png';
$avatar_defaults[$new_avatar] = "Genesis";

// Remove default avatars
unset ( $avatar_defaults['mystery'] );
//unset ( $avatar_defaults['blank'] );
//unset ( $avatar_defaults['gravatar_default'] );
//unset ( $avatar_defaults['identicon'] );
//unset ( $avatar_defaults['wavatar'] );
//unset ( $avatar_defaults['monsterid'] );
//unset ( $avatar_defaults['retro'] );

return $avatar_defaults;
}
[/php]

Remove Avatars
Click for larger image

Set Your Default

Now, WordPress gladly will set your default avatar to the well-known, popular Mystery Man. However, instead of navigating to Settings > Discussion, you can easily set your default as well.
[php]
// Set new avatar to be default
add_action ( 'admin_init' , 'wps_avatar_default');
function wps_avatar_default () {
$default = get_option('avatar_default');
if ( ( empty( $default ) ) || ( $default == 'mystery' ) )
$default = get_stylesheet_directory_uri() . '/images/genesis-48x48.png';
update_option ( 'avatar_default' , $default );
}
[/php]
The known downside of this is that now, Mystery Man can never be chosen so long as this code is active (so it would work well to remove Mystery Man (unset ( $avatar_defaults['mystery'] );) above. This way you can easily control the avatars on your site.

Final Avatar
Click for larger image

Written by Travis Smith · Categorized: Genesis, WordPress

Jan 02 2012

How to Determine Child/Ancestor with is_child() and is_ancestor()

I found this great piece of code at Codebyte.
Put the following in your functions.php file:
[php]
// Check if page is direct child
function wps_is_child( $page_id ) {
global $post;
if( is_page() && ( $post->post_parent == $page_id ) ) {
return true;
} else {
return false;
}
}
[/php]
[php]
// Check if page is an ancestor
function wps_is_ancestor( $post_id ) {
global $wp_query;
$ancestors = $wp_query->post->ancestors;
if ( in_array( $post_id, $ancestors ) ) {
return true;
} else {
return false;
}
}
[/php]

Written by Travis Smith · Categorized: WordPress

Dec 27 2011

Adding Contextual Help Tab to Edit/Add New Post/Page

It is fairly simple and straightforward on how to add contextual help tabs to various admin pages, and with the imminent advent of Genesis 1.8, adding contextual help will be as simple as a help() method. There are also a wide variety of great tutorials on how to add contextual help to admin pages, such as Justin Tadlock's Adding contextual help to plugin and theme admin pages.

However, there aren't any tutorials (at least that I could find) on how to add contextual help to edit/add-new post pages. So while I believe this may not be the best way to do this, it works! Being a pragmatist, it works for me!

[php]
// Add contextual help
add_action( 'add_meta_boxes' , 'wps_help' , 10 , 2 );
function wps_help ( $post_type , $post ) {
if ( 'page' == $post_type ) {
$my_help_tab_content = '<p>' . __( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam varius iaculis dui, eu ultricies velit consectetur pellentesque. Phasellus tortor mi, tempor eget pulvinar eu, sollicitudin ut eros. Quisque fermentum dolor elit. Aenean varius nisi placerat lectus elementum fringilla. Aenean at augue mauris, eu euismod mauris. Integer ac eros in ligula pharetra pretium. Pellentesque vel orci nibh. Pellentesque gravida velit ac lacus egestas eget imperdiet metus egestas. Maecenas tellus ligula, molestie ac pharetra id, tristique eu velit. Phasellus id quam in mi tristique gravida eget in quam. Cras ornare leo sed dui lobortis congue.') . '</p>';

get_current_screen()->add_help_tab( array(
'id' => 'my-help-id',
'title' => __( 'My Help Tab' ),
'content' => $my_help_tab_content,
) );
}
}
[/php]

Written by Travis Smith · Categorized: WordPress

  • « Previous Page
  • 1
  • …
  • 14
  • 15
  • 16
  • 17
  • 18
  • …
  • 25
  • Next Page »
  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

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