How to Display a List of WPForms Using a Shortcode

Would you like to display a list of WPForms on your site? You may want to provide a list of forms publicly (or even privately with a password) on your site to any visitor just by adding a shortcode to that page and you can easily achieve this by adding a small PHP snippet to your site. In this tutorial, we’ll show you the steps to complete this.

Creating the shortcode

First, you’ll need to add this code snippet to your site. This snippet creates a shortcode that you can use on any post, page, or widget area on your site to display a list of all the forms created with WPForms.

If you need any help in adding code snippets to your site, please take a look at this tutorial.

/**
 * Create shortcode to display all form titles in a list.
 *
 * Basic usage: [wpforms_all_forms]
 *
 * @link https://wpforms.com/developers/how-to-display-a-list-of-wpforms-using-a-shortcode/
 */

add_shortcode( 'wpforms_all_forms', function() {
   $args = [
      'post_type' => 'wpforms',
      'post_status' => 'publish',
      'posts_per_page' => -1,
    ];

    $posts = wpforms()->form->get();
    $forms = wp_list_pluck( $posts, 'post_title' );
   return implode( '<br>', $forms );
} );

Displaying a list of WPForms

Once you’ve added the snippet above to create the shortcode, you’ll need to add this shortcode to a page, post or widget area on your site in order for the list of WPForms to display.

For our tutorial, we’re not using a page builder but WordPress Gutenberg Shortcode block to add in our shortcode to the page.

Simply add [wpforms_all_forms] to the page and click Publish and you’ll now see a complete list of your WPForms available.

Add the shortcode to any post, page, or widget area to display a list of all your forms

Most popular page builders also have a similar block in their builders. Please check with your specific page builder’s documentation to find out how best to add a shortcode to a page.

And that’s it! You’ve now created a shortcode that you can use to display a list of all your forms created with WPForms. Would you like to also create a shortcode to display a list of entries for each form? Take a look at our tutorial on How to Display Form Entries.