• Resolved Tom De Smedt

    (@steven_gardner)


    Hi,
    I have a few lines in my theme that include small sections of code for my theme welcome screen but the theme checker suggests I use get_template_part().

    I have no idea how I can get this to work. I’ve tried following the get_template_part() docs but with no luck.

    Current code:

    require_once( get_template_directory() . '/inc/admin/welcome-screen/sections/intro.php' );

    the above code is nested in my theme: inc/welcome-screen/

Viewing 4 replies - 1 through 4 (of 4 total)
  • I believe that wordpress includes the file so I don’t think you need to use the required_once statement.

    The get_template_part retrieves a file from your current template directory.

    For Example, If you wanted to use a different header file you would use get_template_part(‘header’,’second’) and wordpress would look for the file header-second.php.

    If you wanted to use a file called single-content.php you would use the command get_template_part(‘single’,’content’);

    if the file is stored in a subfolder like lib/single-content.php you would use the command get_template_part(‘lib/single’,’content’);

    hope that helps

    Thread Starter Tom De Smedt

    (@steven_gardner)

    Hi MrTom414,

    Thanks for your answer but this file is a custom file in my theme so WordPress doesn’t include it unless I tell it.

    The file is intro.php nested deep in my theme structure. No matter how I try to implement get_template_part() it never includes the file.

    Maybe someone could write the get_template_part code with my path and file structure.
    I’m stumped with this.

    Theme checker plugin just reports this as Info but I’d like it to pass the checker with no info notices.

    Thanks
    Steven

    If you’re using get_template_part(), you don’t need to call get_template_directory(), as get_template_part() starts from your theme folder automatically, even if the PHP file that calls get_template_part() is located in a subfolder of your theme folder. So no matter where you are, you have to pass a full relative path, starting from the theme’s folder:

    get_template_part( 'inc/admin/welcome-screen/sections/intro' );

    It also automatically appends the extension, so this is all you need.

    Thread Starter Tom De Smedt

    (@steven_gardner)

    Brilliant Thanks!

    S

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Getting get_template_part to work’ is closed to new replies.