Using WordPress to Create a Micro-Site within an Existing Theme

One trend in content management has become pretty clear in recent years. Increasingly, site administrators are creating so-called “micro-sites,” or websites within a website, that contain completely different posts, styling, and other features. These micro-sites often appear in the form of digests, magazines, social media repositories, and other types of website that necessarily need to be separated from a site’s main content.

Sure, these micro-sites could be created with an entirely separate installation of the WordPress software and placed in a subdomain, but that’s not exactly easy on readers or website administrators when it comes to creating and sharing information with the wider Internet population. Instead, these micro-sites are so named because they are all managed by the exact same WordPress installation, and even themed with the exact same theme. But, instead of simply using categories to define their unique content, micro-sites rely on an entirely new post time and a micro-theme (or theme within a theme) to stylize this walled garden of novel information.

This technique is rather advanced and makes use of both a custom-designed plugin and a custom-developed addition to the theme-specific functions.php file. WordPress developers who are seasoned in creating themes and crafting custom lines of PHP will feel right at home, while new developers might want to stick, momentarily, to simply delineating their site’s sections using standard tags and categories. That said, those brave enough to take on the task will need to get started right way by creating their own plugin to define a custom post type for the new site.

Step 1: Creating a Plugin That Separates Micro-Site Posts from Homepage Posts

WordPress ships with exactly one post type, known as “the_post.” It’s not really very creative, and it doesn’t have to be. After all, the vas majority of this content management platform’s users are only interested in posting one continuous stream of posts to just one website within their domain’s purview. But for those who are considering creating a second publication that needs access to the same WordPress publishing tools, it is both possible and necessary to create an entirely new post that interacts with the database in an entirely new way.

This feature must be applied universally, and that’s why a functionality plugin is the exact way to accomplish this task. Making a new post type theme dependent, by using the functions.php file found in the current theme’s directory, would wreak utter havoc on a website the moment a new theme was installed. So, here’s the code that defines a new post type within a standalone PHP functionality plugin:

function magazine_post_type() {

register_post_type( 'magazine_',

array(
'labels' => array(
'name' => __( 'Magazine Posts' ),
'singular_name' => __( 'Magazine Edition' ),
'add_new_item' => __( 'Create a New Edition' ) ),

'exclude_from_search' => true,
'capability_type' => 'page',
'has_archive' => true,
'menu_position' => 10,
'public' => true,
'publicly_queryable' => false,
'rewrite' => array( 'slug' => 'magazine', 'with_front' => true ),
'show_ui' => true,
'supports' => array( 'editor', 'title', 'thumbnail', 'excerpt' ),

add_action( 'init', 'magazine_post_type' );

If you’ve recently been learning about WordPress plugins, customized control panels, and theme-defined functions via the functions.php file, this would sort of serve to act as the “capstone course” of WordPress education. Included in just this small plugin is a post type, an action, and several arrays. The full functionality of this plugin doesn’t require filters or functions but, if it did, that would serve to use every element of WordPress development in tandem in just one simple plugin. That’s pretty remarkable.

The work above defines a new post type and sets the options available to these new posts in the resulting array. In this array that begins with exclude_from_search, we are telling the WordPress installation not to show the magazine posts in a search, while telling it to create an archive of the posts and place it at menu position ten. The new post type will not be publicly queriable, it will have a “magazine” slug, and it will support the entry title, editor, thumbnail (featured image) and excerpt fields. Everything omitted from this array is not supported or is defined by the WordPress defaults.

At the end of the plugin above, an action is added that creates the post type and initializes it within the WordPress Dashboard. As far as creating a unique post type within this WordPress installation, the above plugin takes care of everything and reduces the job to just a few lines of code within arrays. There is no additional work to be done in order to define this new post type. Instead, users should now move on to defining their “theme within a theme.” This is an optional step, to be sure, but many users who create micro-sites are completing this process because they want their walled-off content to adhere to a completely different (or walled-off) design. This separate design sort of sets the boundary between the homepage and the new micro-site, so it’s a good idea to engage in this process and create a new look for this new content.

Step 2: Moving from Plugins to Functions When Creating a new Design Type

The above functionality plugin was created because it enables an entirely new post type, and forcing that to be a theme-based function would cause all kinds of problems if the site administrator forgot to transfer the post functionality to the new theme’s functions.php file. However, the next step in this tutorial will not be placed in that functionality plugin. Instead, this part of the tutorial directly modifies how an individual theme behaves. For this reason, the code below must be placed into the current theme’s functions.php file instead. Again, this is essentially the master class of WordPress development for those who consider themselves advanced WordPress coders. Let’s look at the relevant code below and how it modifies the presentation of the current WordPress theme.

add_action( 'wp_print_styles', 'magazine_edition_styles' );

function magazine_edition_styles() {
if ( is_post_type_archive( 'magazine_' ) || is_singular( 'magazine_' ) ) {
wp_dequeue_style( 'master' );
wp_enqueue_style( 'magazine', THEME_CSS_URI . '/magazine.css', null, '0.1' ); } }

The function above is a straightforward one. It adds the magazine_edition_styles action to the existing wp_print_styles action that controls the display of the current WordPress homepage and all of the standard templates. The magazine_edition_styles action is told only to apply when a magazine post is being read, and when that happens, WordPress is instructed to ditch a website’s regular stylesheet and instead using a specialized stylesheet named magazine.css. That file is placed within the current theme’s main directory right alongside the traditional stylesheet.css file, and this is indicated by the THEME_CSS_URI variable that instructs the function to look in that directory for the stylesheet.

This allows the magazine edition of the website’s content to be presented in a radically different way from the content that is presented on the traditional homepage. Indeed, it is not responsible for printing any of the current classes, IDs, or form elements that are stored within the much broader (and bigger) WordPress stylesheet. Separate this special micro-site from the other sections of the website stylistically is a wonderful way to wall content off and encourage users to read this new “magazine” section in a new way, perhaps less frequently. It’s also a great way to communicate the magazine edition’s new mission, as compared with the production website.

Step 3: Don’t Forget to Create New Template Files for the Micro-Site

The new stylesheet is a great way to wall off the micro-site’s content from the rest of the site’s content stylistically. But it’s virtually useless if new template files aren’t created to utilize the specialized styles. This is the time to create an index page, as well as an archive page, for the new micro-site’s content. These template files will be created in normal PHP code, and they’ll be assigned a custom name so that they can be viewed and assigned within the “New Page” dialog of the WordPress Dashboard.

These template files will likely also require their own WordPress header and footer templates, so duplicates of those essential files will need to be made with a unique name; they’ll be included using standard PHP code rather than the WordPress variable that works for general, non-micro-sites.

Step 4: Test it Out and Make Necessary Changes to PHP, XHTML, or CSS

The process of creating a custom post type and defining a micro-site within WordPress is now complete. However, despite its brief lines of code and relatively easy execution for the advanced WordPress developer, this is actually a pretty broad and advanced thing to do. A theme’s template files were modified, a new stylesheet was created, a plugin was custom-developed, a new post type was created, and a theme-specific function was created to disown the standard stylesheet in favor of the new one specific to the micro-site. If that doesn’t sound like a goldmine for accidental errors and bugs, certainly thing ever will.

Once every change has been committed and uploaded to the server, it’s time to employ all of the site’s administrators to make sure that everything is still working perfectly. Creating new post types can sometimes cause problems with existing posts, and custom-developed plugins have been known to throw some PHP errors upon first execution. Looking into every aspect of this new functionality is the key way to ensure that users will not be inconvenienced by errors, misplaced content, or stylesheets that blind them or force them to read similar content on a competing website.

When all of the kinks have been ironed out of this new website, administrators should begin filling the micro-site with new and exciting content, encouraging their users to join them on an all new journey of content creation and interaction.

Author: (40 Posts)

Vladislav Davidzon is the principal of US-based online marketing consultancy Vladislav Davidzon & Associates, developing integrative solutions through high impact search engine optimized WordPress websites for socially responsible customers of all sizes around the world.

Comments