Sorry my PHP skills are lacking.

I want to use a php include in WP but I'd like to get the file path with <?php get_template_directory(); ?>

I can't figure out how that would look.

My non WP file looks like this:

<?php include 'inc/social.php'; ?>

Basically I don't know how to string two PHP commands together get_template_directory + include.

  • For a parent theme or child theme? Feb 23, 2014 at 23:53

1 Answer 1


get_template_directory() and get_stylesheet_directory() both pull form the wp-content/themes directory. The difference being that the former always pulls from the parent theme directory.

Neither take parameters, so you just concatenate the rest of the path to the string returned from the appropriate function. That is:

include get_template_directory().'/inc/social.php';

If your file is not in your theme directory, you cannot use those functions. They are very specifically theme functions.

  • This is correct. It should be noted that WordPress has a helper function get_template_part() for including sub-templates. Feb 24, 2014 at 2:06
  • I thought about get_template_part but this strikes me as the kind of file that should not be easily replaceable.
    – s_ha_dum
    Feb 24, 2014 at 3:08
  • Thank you. Works perfectly. I am now interested in get_template_part. I'll look into that.
    – user47996
    Feb 24, 2014 at 17:55

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.