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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *