Placeholder Shortcodes

When building out modular templates, we output content in two different ways based on the context.

The full output (content, markup, dynamic content) is used for display on the frontend. A simplified content-only version (no theme markup, no dynamic content) is saved to the post_content field for search indexing and future-proofing.

The dynamic features of the module are included as placeholder shortcodes – shortcodes that haven’t been built out and are currently disabled.

If I have a “Recent Posts” module that includes title, intro content, and number of posts to display, the content we add to the post_content¬†field may look like this:

if( !empty( $module[ 'title' ] )
  echo '<h4>' . esc_html( $module[ 'title' ] ) . '</h4>';
if( !empty( $module[ 'intro' ] ) 
  echo wpautop( $module[ 'intro' ] );
echo '[module_recent_posts count="' . intval( $module[ 'count' ] ) . '"]';

Then towards the bottom of the modules.php file we’ll have:

 * Future Developer: These placeholder shortcodes are for you. If you are not using the module
 * template in your new theme but would like to retain the dynamic features (ex: recent posts),
 * build out these shortcodes. The shortcodes have been included in the post content, but the
 * `__return_false` makes them not visible on frontend. This way you can add back that functionality
 * without having to manually update every page that needs it.
add_shortcode( 'module_recent_posts', '__return_false' );

When the theme changes and the “Modules” template is no longer available, it will use the default template and output the post content. These shortcodes will be in the content area, but not appear on the frontend because of the __return_false.

When the client or a future developer changes themes, they can:

  1. Build a modular template for the new theme, in which case the post_content is not used on the frontend.
  2. Build out these shortcodes, so the post_content field is used and the shortcode displays a listing of recent posts in the new theme’s style.
  3. Don’t do anything. No recent posts are shown on the page, but the unused shortcodes are not visible to site visitors.

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk