This is just the beginning

What did I learn about WordPress Starter Content?

I spend the last two days playing with Starter Content option that was introduced in WordPress 4.7. I’ve heard about this a long time ago but I never took the time to step back and give it a try. Since I’m working on a new theme for WordPress.org, I was thinking that it’s time to see how this feature can help me.

Why do you need this starter content and, most important, why a new article when there are already some very helpful resources out there?

Well, first of all, I think that I learned a lot of things in these two days. And, second of all, I really have to share this. Other users that might wanna use this on their theme really need to know a few things. Are you ready?

There’s an article that can be used as a starting point

There’s this article that you can use to learn some basic things like when was this option added to WordPress or how should the config look like. However, there are just some small pieces of code that you can copy and hope for the best. I’m saying this because some parts are not actually working but we’ll talk about that a bit later.

There are already a few elements included by default

Here’s the default config that’s merged with the one that you’re adding to the theme (or to a plugin if going this way): https://github.com/WordPress/WordPress/blob/master/wp-includes/theme.php#L2002

Basically, you have a few widgets, menus, and pages that you can already use without being needed to create them from scratch. Basically, you’ll be able to set the homepage and the posts page very easily with just a few lines of code. However, there’s no post included in this core content which looked a bit odd to me. I mean, WordPress main element is… the post. Why are only pages the only type of posts included by default? Well, the answer to this question leads me to the next point of my post.

The posts cannot be used with starter content

This is the main part that almost made me give up and delete everything I’ve done. However, I tend to at least understand why is a thing happening and that’s what I was gonna do this time too. So, after a couple hours, I made the connection that the posts created by starter content were saved with the status of auto-draft and that’s why nothing was showing on the blog archive. Basically, what I was looking to add some posts (11 to be more precise) and show all of them on a page through some custom widgets. Everything worked fine but the posts part was a dead-end. However, the solution that I used, even though it’s not a fancy one, was this code:

function post_status_customizer_change( $query ) {
	if ( ( 1 == get_option( 'fresh_site' ) ) && is_customize_preview() )
      $query->set('post_status', 'auto-draft');
}

add_action('pre_get_posts','post_status_customizer_change');

Using this code I was able to include the posts in the main loop and get them displayed as needed.

All in all, these were the main things that I learned from playing with the starter content. It’s a nice feature so big shout-out for everybody that worked implementing it. Since the WordPress.org system is still relying on the same default preview content for all the themes, I think that starter content is a breath of fresh air for everybody who wants to stand-out and show what his theme can do.

P.S. This is an article that I wrote at the end of the day, right after I closed PhpStorm. If you see any bad grammar or something wrong, please have mercy. I’m doing my best and still learning 😁

Leave a Reply