Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stuartduff/843e61cacb4cb85eb84f to your computer and use it in GitHub Desktop.
Save stuartduff/843e61cacb4cb85eb84f to your computer and use it in GitHub Desktop.
Add a custom shortcode section to the storefront themes homepage template.
function sf_output_custom_shortcode_section() {
echo '<section class="storefront-product-section storefront-product-category">';
echo '<h2 class="section-title">' . __( 'Music Category', 'storefront' ) . '</h2>';
echo do_shortcode( '[product_category category="music" columns="4" per_page="4"]' );
echo '</section>';
}
add_action( 'homepage', 'sf_output_custom_shortcode_section', 50 );
@inakicalvo
Copy link

inakicalvo commented May 10, 2018

@stuartduff thanks a lot! This lines of code saved my day 👍

@Maksimasc
Copy link

Hello, can't find a homepage file location...

@davidsolsona
Copy link

Great! thanks

@krystyna93
Copy link

I am actually following a WordPress tutorial on WooCommerce that describes this shortcode, so I decided to search this specific method of displaying a product from a specific category, and found it! so thanks.

@Autoservises
Copy link

If I want to do the same with attributes, or attribute properties, what needs to be changed in this code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment