July 14, 2022 | Posted in WordPress
There are countless plugins and widgets available for WordPress users to add extra functionality – from displaying popular posts to allowing users to participate in polls. However, what if you want to add some of that functionality to other places than a page, post, or sidebar? For example, in a WordPress page/theme template file?
In a page or theme template, to enable the special functionality of a shortcode, simply wrap the standard WordPress do_shortcode function with a PHP script – as shown below.
<?php echo do_shortcode("[insert-your-shortcode-here]"); ?>
For example, you are developing a WooCommerce custom theme from scratch and want to display new arrival products on the front page below the slider. Here is the solution
<?php
echo do_shortcode('products limit="4" columns="4" orderby="id" order="DESC" visibility="visible')
?>