Add a Shortcode with Parameters to a Layout

From IThemes Codex
Jump to: navigation, search

Add the shortcode (in this example, we will use [pb_slideshow group="2"], to show a slideshow) to a custom field in your post. In this example, the custom field is named post-slideshow.

Then, add the following code at the end of your functions.php file (but before the closing ?>, if any).

Code

function insert_my_custom_field_shortcode() {
    global $post;
    
    return do_shortcode( get_post_meta( $post->ID , "post-slideshow" , true ) );
}
add_shortcode('insert-slideshow-in-post', 'insert_my_custom_field_shortcode');

Usage

Drag a shortcode into the LoopBuddy layout of your post, and add the [insert-slideshow-in-post] shortcode. The function will retrieve the contents of the custom field (post-slideshow) and insert it where defined in the layout.


← Back to LoopBuddy Codex Home

Personal tools
Namespaces
Variants
Actions
iThemes Codex
Codex Navigation
Toolbox