Include Files in a Theme

If you want to include files in a theme, you can use:

require_once('shortcodes.php');

A better way would be to use get_template_part():

get_template_part('shortcodes');

And that’s why:

get_template_part() is looking for the file in a child theme (if you use one). If this file does not exist, it uses the file from the parent theme. If you use:

get_template_part( 'sidebar', 'primary' );

The function would look for:

  • child theme sidebar-primary.php
  • parent theme sidebar-primary.php
  • child theme sidebar.php
  • parent theme sidebar.php