Built-in Shortcodes

Inside LiveCanvas, as in standard WordPress posts and pages, you can use shortcodes to implement dynamic parts ("PHP code").

The LiveCanvas plugin defines some extremely barebone but powerful shortcodes to simplify your work and get you started quicker.

lc_nav_menu

This shortcode calls the WordPress wp_nav_menu function, passing all shortcode parameters.

It can be used for including the navigation in your header, or wherever you want.

Accepted parameters and default values:

'theme_location' => 'primary',
'container_class' => '',
'container_id' => '',
'menu_class' => '', //TO THE UL
'fallback_cb' => '',
'menu_id' => '',
'depth' => 2,
'walker' => $the_walker,

It is using as a default walker function:

  • the bootstrap_5_wp_nav_menu_walker class, if defined, for Bootstrap 5 support (eg for Picostrap5 theme support)
  • the WP_Bootstrap_Navwalker class, if defined, for Bootstrap 4 support (eg for Picostrap4 theme support)
  • the Understrap_WP_Bootstrap_Navwalker class, if defined, for UnderStrap theme support.

Example

lc_nav_menu theme_location="primary" container_class="" container_id="" menu_class="navbar-nav"

lc_home_url

This shortcode calls the WordPress home_url function.

It's typical use case is in a custom header, to link the logo to the site's homepage.

No parameters are allowed.

lc_get_posts

This shortcode calls the WordPress get_posts function, passing all shortcode parameters.

It can be used for displaying a list of posts of any custom post type.

The simplest use case could be when you want to show a listing of your most recent blog posts in your homepage.

It allows also for custom callback functions, so you can precisely decide how your posts should be rendered.

For more details, please have a look at the post loops documentation page.

Accepted parameters and default values:

///INPUT PARAMETERS
'posts_per_page' => 10,
'offset' => 0,
'category' => '',
'category_name' => '',
'orderby' => 'date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'post_status' => 'publish',
'suppress_filters' => true,
'tax_query' => '', //custom: taxonomy=term_id
///OUTPUT PARAMETERS
'output_view' => 'lc_get_posts_default_view', //SEE APPENDIX BELOW
'output_wrapper_class' => '',
'output_link_class' => '',
'output_number_of_columns' => 3,
'output_article_class' => '',
'output_heading_tag' => 'h2',
'output_hide_elements' => '',
'output_excerpt_length' =>45,
'output_excerpt_text' => '…',
'output_featured_image_before' =>'',
'output_featured_image_format' =>'large',
'output_featured_image_class' => 'attachment-thumbnail img-responsive alignleft'

About the output_view parameter

Possible values: lc_get_posts_listing_view, lc_get_posts_card_view, lc_get_posts_collapsible_view_bs5.

Or your custom callback. Please refer to the post loops documentation page.

Examples

Listing the articles, as Boostrap cards:

lc_get_posts post_type="post" output_view="lc_get_posts_card_view" output_number_of_columns="4" output_featured_image_class="card-img-top" output_article_class="shadow"

Listing the site pages, with links:

lc_get_posts post_type="page" output_view="lc_get_posts_listing_view" output_wrapper_class="list-unstyled" output_link_class="d-block mb-2"

A Live example of the last row, with the parameters above

lc_widgetsarea

This shortcode calls the WordPress dynamic_sidebar function.

It can be used to display a sidebar and it's widgets of course, inside any page, or in the footer for example.

Accepted parameters and default values:

'id' => 'main-sidebar'

lc_get_cats

This shortcode calls the WordPress wp_list_categories function, passing all shortcode parameters.

It can be used for listing your blog categories.

Accepted parameters and default values:

'child_of' => '0',
'current_category' => '0',
'depth' => '0',
'echo' => false, //so we return the output in a string instead of printing it
// INPUT-RELATED PARAMETERS
'exclude' => false,
'exclude_tree' => false,
'hide_empty' => '1',
'hide_title_if_empty' => false,
'hierarchical' => true,
'order' => 'ASC',
'orderby' => 'ID',
'separator' => '<br>',
'show_count' => 0,
'show_option_all' => false,
'show_option_none' => 'No categories',
'style' => 'list',
'taxonomy' => 'category',
'title_li' => 'Categories',
'use_desc_for_title' => 1,
// OUTPUT-RELATED PARAMETERS
'output_view' => 'lc_get_cats_default_view',

lc_get_post

This shortcode returns a specific post's content. Useful to grab LiveCanvas partials. Just pass the post id OR  the slug as parameter.

Accepted parameters and default values:

'id' => ''
'slug' => ''
'post_type' => '' (optional. Set to lc_block|lc_section|lc_partial)

lc_get_gt_block

This shortcode returns a specific post's content, parsing Gutenberg blocks, if present.

Accepted parameters and default values:

'id' => ''

lc_dummyshortcode

This is just a test shortcode to display a test message. No parameters are allowed.

lc_get_cf

This shortcode returns the value of a specified custom field of the current page / post.

Accepted parameters and default values:

'field' => '',