A shortcode is a specific code that lets you do nifty things without messing with other things. Shortcodes can show specific post or custom post type details, embed files or create objects i.e slider, Gallery and more that would normally require lots of complicated, ugly code in just one line.
Shortcodes are a great way to display various contents without doing the same stuff again and again. Shortcode = shortcut.
How to create shortcode?
The all we need to add and create a function with add_shortcode to do the STUFF. Here is one example
add_shortcode( 'sitename', 'site_name' ); function site_name() { return '<a href="' . get_bloginfo( 'url' ) . '" title="' . get_bloginfo( 'sitename' ) . '">' . get_bloginfo( 'name' ) . '</a>'; }
Usage:
[sitename]
This will Output the Blog URL with Name and Title.
Shortcodes in Genesis
Genesis Framework offers various important shortcodes so you don’t need to look for any help setting up the basic designs and looks. Genesis shortcodes can be used anywhere with the help of Genesis hooks and can be combined with Custom Post types post.
This article is for reference only to preview the untapped or the types of shortcodes offered by Genesis.
If you are wondering why your shortcodes are not working in HTML widgets here is the code that will make it work. Add this in functions.php
//* Allow shortcodes to execute in widget areas add_filter('widget_text', 'do_shortcode');
Shortcode in Functions.php
Let suppose you want to show WP-Postratings on the single post, What we have to use it
add_action('genesis_entry_content', 'shortcode_wp_postratings'); function shortcode_wp_postratings() { if ( is_single() ) { echo do_shortcode('[ratings]'); } }
Post Shortcodes
Here is the list of shortcodes that can be used in the Entry Header (Post info, entry-meta) and Entry Footer (Post meta) sections.
1. Post Published date
[post_date]
This shortcode produces the date of Post publication. List of attributes for this shortcode:
- format – The format for the date. Defaults to the date format configured in your WordPress options.
- before – Text/markup to place before the post date.
- after – Text/markup to place after the post date.
- label – Text to place before the post date.
Example:
Output:
Shortcode:
[post_date format="F j, Y" label="Published on: "]
Published Time
[post_time]
This shortcode produces the time of Post publication. List of attributes for this shortcode:
- format – The format for the time. Defaults to the time format configured in your WordPress options.
- before – Text/markup to place before the post time.
- after – Text/markup to place after the post time.
- label – Text to place before the post time.
Example:
Output:
Shortcode:
[post_time format="g:i a"]
See the WordPress Codex for more information on formatting date and time.
2. Post Modified date
[post_modified_date]
This function produces the date on which the post was last modified. Here is a list of attributes for this shortcode:
- format – The format for the date. Defaults to the date format configured in your WordPress settings.
- before – Text/markup to place before the post modified date.
- after – Text/markup to place after the post modified date.
- label – Text to place before the post modified date.
Example:
Shortcode:
[post_modified_date format="F j, Y" label="Last Modified: "]
Post Modified time
[post_modified_time]
This function produces the time at which the post was last modified. Here is a list of attributes for this shortcode:
- format – The format for the time. Defaults to the time format configured in your WordPress settings.
- before – Text/markup to place before the post modified time.
- after – Text/markup to place after the post modified time.
- label – Text to place before the post modified time.
Example:
Shortcode:
[post_modified_time format="g:i a"]
3. Post Author Name
[post_author]
This shortcode produces the name (display name) of the author of that single post. List of attributes for this shortcode:
- before – Text/markup to place before the post author name.
- after – Text/markup to place after the post author name.
Example:
Output:
Shortcode:
[post_author before="" after=""]
4. Post Author Post link
[post_author_posts_link]
This shortcode produces the name (display name) of the author of that single post. List of attributes for this shortcode:
- before – Text/markup to place before the post author link.
- after – Text/markup to place after the post author link.
Example:
Output:
Shortcode:
[post_author_posts_link before="by" after=""]
5. Post Comments
[post_comments]
This function produces the Comment URL with total comments count. Here is a list of attributes for this shortcode:
- zero – Text to display if zero comments on the post.
- one – Text to display if one comment on the post.
- more – Text to display if more than one comment on the post.
- hide_if_off – Enable the comment link even if comments are off.
- before – Text/markup to place before the post comment link.
- after – Text/markup to place after the post comment link.
Example: Default
Output:
No Comments: No Comments
1 Comment: 1 Comment
Multiple Comments: 7 Comments
Shortcode:
[post_comments zero="No Comments" one="1 Comment" more="% Comments" hide_if_off="disabled"]
6. Post Tags
[post_tags]
This function produces the list of tags with their archive link.
- sep – Separator between post tags.
- before – Text/markup to place before the tag list. Default “Tagged With: “
- after – Text/markup to place after the tag list.
Example:
Output:
Shortcode:
[post_tags sep=", " before="Tags: "]
7. Post Categories
[post_categories]
This function produces the post categories with their archive link.
- sep – Separator between post categories.
- before – Text/markup to place before the post category list. Default “Filed Under: “
- after – Text/markup to place after the post category list.
Example:Filed Under: Free Content, Genesis Tutorials
Output:
Posted Under: Free Content, Genesis Tutorials
Shortcode:
[post_categories sep=", " before="Posted Under: "]
8. Post edit
[post_edit]
This function produces the edit post link for logged in users. List of attributes for this shortcode:
- link – Text for edit link. Default “(Edit)”
- before – Text/markup to place before the edit post link. Default “Filed Under: “
- after – Text/markup to place after the edit post link.
Example:
Output:
Shortcode:
[post_edit before="" after=""]
Note: This link displays only for logged-in users with a role that permits editing.
Footer Shortcodes
Below is a list of shortcodes that can be used in the site footer.
1. Back to Top
[footer_backtotop]
This function produces the “Return to Top” link. List of attributes for this shortcode:
- text – Default: “Return to top of page”
- href – assign to which div this link is anchored. Default: #wrap
- nofollow – assign nofollow to the rel attribute in the link to backtop. Default set to true.
- before – Text/markup to place before the “Return to Top” link.
- after – Text/markup to place after the “Return to Top” link.
Example:
Output:
Shortcode:
[footer_backtotop]
2. Footer Copyright
[footer_copyright]
This function produces the copyright text.
- copyright – Default: ©
- first- Text/markup to place between the copyright symbol and the copyright date.
- before – Text/markup to place before the copyright.
- after – Text/markup to place after the copyright.
Example:© 2023
Output:
© 2015–2023
Shortcode:
[footer_copyright first="2015"]
3. Child Theme
[footer_childtheme_link]
This function produces the child theme link.
- before – Text/markup to place before the childtheme link. Default: ·
- after – Text/markup to place after the childtheme link.
Example:·Genesis Sample
Output:
· Genesis Sample
Shortcode:
[footer_childtheme_link before ="· "]
5. Child Theme
[footer_genesis_link]
This function produces the genesis theme link. Here is a list of attributes for this shortcode:
- before – Text/markup to place before the genesis theme link.
- after – Text/markup to place after the genesis theme link.
Example:Genesis Framework
Output:
Genesis Framework
Shortcode:
[footer_genesis_link]
6. by StudioPress
[footer_studiopress_link]
This function produces the StudioPress link.
- before – Text/markup to place before the StudioPress link. Default: “by”
- after – Text/markup to place after the StudioPress link.
Example:by StudioPress
Output:
by StudioPress
Shortcode:
[footer_studiopress_link]
7. WordPress
[footer_wordpress_link]
This function produces the WordPress link.
- before – Text/markup to place before the WordPress link.
- after – Text/markup to place after the WordPress link.
Example Output:
WordPress
Shortcode:
[footer_wordpress_link]
8. Log in / Log out
[footer_loginout]
This function produces the log in/out link.
- redirect – Set redirect to a URL on login.
- before – Text/markup to place before the log in/out link.
- after – Text/markup to place after the log in/out link.
Example:Log in
Output:
Log in
Shortcode:
[footer_loginout redirect="http://www.studiopress.com/features/genesis"]
You can even write your own shortcodes and can use plugins like Shortcode Ultimate which offers various features and functionality via shortcodes without writing messy codes.
Display post shortcode is an example of powerful Plugin includes some great features with tiny shortcodes.
One more Example of A Plugin is Pods. Pods offer various rich functionality using template shortcodes and other shortcodes which is really powerful. It can be mixed with Genesis like Bread and Butter.
Do share your experience using shortcodes in Genesis child theme.
Reference:
https://my.studiopress.com/documentation/customization/
Thank you so much.
It is an amazing post and you explained in a detailed way. Nice to see this here. I will bookmark your blog for more details. Keep sharing the new things like this.
Good stuff, can you tell me how to use hero slider shortcode in genesis so it shows up in actual hero section (where featured images go) I am just trying to make a basic hero banner; title, subtitle, a back image. I hope that makes sense. I have Breakthrough child theme in genesis which has default banners/ pictures throughout the theme. I can replace it with a featured image on each page but I can’t figure out how to make banners.
Please share the code and screenshot in chat so I take a look into this.