What is demo content?

When a user activates a theme, they have an expectation of seeing their photos, theirs shop, their contributors and all of their content with a new style or twist. Themes provide this ability to showcase user content in different ways. How a theme gets that content is what we look for. When there is no content a theme should not show anything. This has been an issue in the past and this will hopefully add more information to that. Sounds simple, right?

Yes and no.

What about default settings?

Brilliant question to ask because themes need to have a basic, or default, setting in order to display user content. Let’s look at a good example of this. Using a basic loopLoop The Loop is PHP code used by WordPress to display posts. Using The Loop, WordPress processes each post to be displayed on the current page, and formats it according to how it matches specified criteria within The Loop tags. Any HTML or PHP code in the Loop will be processed on each post. https://codex.wordpress.org/The_Loop. as an example:

if( have_posts() ):
	while( have_posts() ):
		// our content if there are actual posts to loop over
	// now if there is nothing to show we can simply end it here -or- show a default message
	printf( __( 'There are no posts, how about creating <a href="%s">one</a>?', 'textdomain' ), esc_url( admin_url( 'post-new.php' ) );

Looks simplistic. But what if you wanted to add a message letting the user know they have nothing to show or point them in the right direction to create a post. We don’t want the entire world to know or even see that link, right? This message has to have meaning for the user and not the world to see. This is where some may get tripped up because some will want to use what we consider demo content. So what we can do is add a capability check.

// check to make sure the current user can edit posts
if ( current_user_can( 'edit_posts' ) ){
	printf( __( 'There are no posts, how about creating <a href="%s">one</a>?', 'textdomain' ), esc_url( admin_url( 'post-new.php' ) );

What constitutes demo content?

By making sure that we use the right capability we can ensure that only the right people will see those messages. What we want to avoid is when a user activates the theme they are not advertising the theme. This is essentially dummy content or demo content. A good example is the following that is hard-coded to a theme’s footer:

<?php if ( !dynamic_sidebar( 'bottom-sidebar' ) ): ?>
<div class="col-md-3">
	<div class="footer-widget clearfix">
		<h4><?php _e( 'About our Theme','textdomain' ); ?></h4>
		<p><?php _e( 'our theme is the greatest in the land, and none shall pass!.', 'textdomain' ); ?></p>
		<div class="footer-social-icon">
			<a href="#" class="facebook"><i class="fa fa-facebook"></i></a>
			<a href="#" class="twitter"><i class="fa fa-twitter"></i></a>
			<a href="#" class="skype"><i class="fa fa-skype"></i></a>
			<a href="#" class="google-plus"><i class="fa fa-google-plus"></i></a>
<div class="col-md-3">
	<div class="footer-widget clearfix">
	  <h4><?php _e( 'Contact us!','textdomain'); ?></h4>
		<div class="contact_link">
			<a href="#"><i class="fa fa-home"></i><?php _e( '1492 Blue Lane','textdomain'); ?></a>
			<a href="#"><i class="fa fa-calendar-o"></i><?php _e( 'Springfield, 65721','textdomain'); ?></a>
			<a href="#"><i class="fa fa-phone"></i><?php _e( '(800)review-me','review-team'); ?></a>
			<a href="#"><i class="fa fa-envelope-o"></i><span><?php _e( 'support@example.net','textdomain'); ?></span></a>

The above code is used as an example of what not to do. The code is used to make the preview look good when there are no in-use widgets. Yes, the preview could use a little love and there are some that are working on that. That still does not mean every theme has to bypass this.