0

I'm correctly developing my own theme and so far I got: index, header, footer, functions and style files. The list will go on as I'm progressing with my theme. But I'm considering to use more than one theme at this site with total different files and I'm thinking of using simply different names for files instead the original ones, so instead of header.php it would be blabla.php and so on. With different data inside them, of course. So... therefor I have very important questions:

Would this method may make any conflict in WP core or something like this?

9
  • 1
    get_header and get_footer already provide a mechanism for loading different header and footer templates. I suggest spending some time with the Codex and familiarizing yourself with these functions, as well as how the Template Hierarchy works and associated filters.
    – Milo
    Oct 23, 2015 at 18:48
  • So, it should be fine to use different files as I thought to, correct? No conflict etc? I'm impatient with WP :) Thanks for answer!
    – baicrout
    Oct 23, 2015 at 19:23
  • I'm not sure what you mean by conflict. You haven't said how you plan to use these files with names that don't follow the template hierarchy.
    – Milo
    Oct 23, 2015 at 19:30
  • I want it to use as a simply two different sites. I think the template hierarchy shouldn't be the issue because I'll make index-n.php instead of index.php and so on... Am I catching this right or not?
    – baicrout
    Oct 23, 2015 at 19:41
  • The use of this files will be alike with the original ones. say, index-n will include footer and header(just different than the index have)
    – baicrout
    Oct 23, 2015 at 19:43

2 Answers 2

1

You probably are over complicating things for yourself. You can use the template_include filter for that

add_filter( 'template_include', 'wpse_206394_template', 99 );

function wpse_206394_template( $template ) {

    if ( template should be blabla  ) {
        $new_template = locate_template( array( str_replace('.php','-blabla.php',$template) ) );
        if ( '' != $new_template ) {
            return $new_template ;
        }
    }

    return $template;
}

but most likely you can get the same effect with proper use of the template hierarchy.

2
  • Thanks for helping me out! So, this code should go... where? in plugins directory? or simply at the begging of index.php inside my theme folder? I'm not really sure about this template hierarchy thing yet, but I'm totally new to WP, so I'll dig into it more closely tomorrow.
    – baicrout
    Oct 23, 2015 at 21:02
  • In your theme's functions.php. But frankly if you are not familiar with the hierarchy maybe you should stop and get the knowledge first as this is an essential wordpress theme concept. Oct 23, 2015 at 21:06
0

You can use the get_template_part to load different files into your template, using whatever combination of name/slug you want. Works friendly with child themes also, which might be worth investigating if you want to have multiple different themes.

The documentation says:

Function Reference/get template part

Load a template part (other than header, sidebar, footer) into a template. Makes it easy for a theme to reuse sections of code and an easy way for child themes to replace sections of their parent theme.

Pretty easy to use too:

# if you want to include blabla.php into your template
<?php get_template_part( 'blabla' ); ?> 
1
  • Thanks for a reply. I don't see a use of it at this moment, I'm probably dumb :) But, if I can use bla.php as my index.php and include in my bla.php the get_header and get_footer with the right word inside the brackets so it would be like header-bla.php or something.
    – baicrout
    Oct 23, 2015 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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