I'm trying to create certain modulair blocks which I can add to multiple pages in Wordpress. But I use sidebar-[name].php files for this, what is the best practice for this? Should you add them to a function or add them in a sidebar...

It feels Kinda off using many sidebar's. It would be nice if I could add them to a sub-folder in the template. Checkout the image. How do you do this?

enter image description here

  • It's a bit unclear what you're asking here. Are you asking how to include template parts in a WordPress Theme, or how to use PHP to modularize a template? Commented Oct 25, 2013 at 21:26
  • Both actually. As you can see in the screenshot my base folder is getting crowded with files. So I want to modularize the theme using smaller files in folders.
    – Remi
    Commented Oct 26, 2013 at 8:42

2 Answers 2


I would say to add them as template parts as in content-[name].php. For instance in page.php you could have something like:

<?php while ( have_posts() ) : the_post(); ?>
            <?php if (is_page( 'home' ) ){
                 get_template_part( 'content', 'benefits' );
                } elseif (is_page( 'Contact' ) ){
                 get_template_part( 'content', 'contact' ); 

            get_template_part( 'content', 'popup' ); ?>
        <?php endwhile; // end of the loop. ?>

It seems to make more sense as it is content after all.


Who says you can not put template files into sub-directories?

Your custom-templates can be put wherever you want them to be - because it is you who includes them, anyway.

If you see the Codex on get_template_part, you find the following:

get_template_part( 'partials/content', 'page' );
  • 1
    Nice addittion. So I added all the files to a "partials" folder, cleaned up the root very nice.
    – Remi
    Commented Oct 26, 2013 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.