In another tutorial I am writing, one for non-coders, I needed a way to pull in custom fields into the post. Currently (and sadly), in Genesis there is no way to do this; however, Genesis does have a great php function that already does this, genesis_get_custom_field(). So turning that into a shortcode is rather easy. Just add the following to your functions.php code:
[php]
add_shortcode( 'post_field', 'genesis_post_field_shortcode' );
/**
* Returns the value of a custom field.
*
* Supported shortcode attributes are:
* field (field name),
*
* @param array $atts Shortcode attributes
* @return string Shortcode output
*/
function genesis_post_field_shortcode( $atts ) {
$defaults = array(
'field' => '',
);
$atts = shortcode_atts( $defaults, $atts );
return genesis_get_custom_field( $atts['field'] );
}
[/php]
To use the shortcode, you just insert [ post_field field="my_field_name"] (without the space in the front) and boom! It works!
Aram says
Hey Travis
I’m trying to get this working on my site with no luck. I’m sure I’m just not doing something correct. Any help would be much appreciated.
http://thinkaram.com/apparel/get-your-keirin-classic-t-shirt/
Thanks
Travis Smith says
Hello Aram,
So do you know what the problem is? I am not really sure how to help you?
Thanks,
Blogging Tips says
I want to add the shortcodes for notes, alerts, downloads and different color boxes !! Can we have the functionality so that we can have this feature in post visual editor only!!
Travis Smith says
Hello,
Yes you can, but you will need to download a shortcode plugin that will do this for you. There are some on codecanyon, I believe.
Thanks,
Travis