1

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.

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

1 Answer 1

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.

3
  • This is correct. It should be noted that WordPress has a helper function get_template_part() for including sub-templates. Commented 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. Commented Feb 24, 2014 at 3:08
  • Thank you. Works perfectly. I am now interested in get_template_part. I'll look into that. Commented 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.