Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

For organisation, I'm trying to split up the functions.php file into separate files. In particular the functions for shortcodes in a separate file, with the shortcodes being defined in functions.php. Here's the code in the functions.php:-

locate_template( array( 'inc/shortcode-functions.php' ), true, true ); 
add_shortcode( 'abc-row', 'echo_abc_row' );
add_shortcode( 'abc-span', 'echo_abc_span' );

I have taken the code out of inc/shortcode-functions.php into the functions.php, so does appear to work, and no error is coming up in debug mode, so I'm a bit stumped. Any ideas?

share|improve this question

2 Answers 2

The locate_template() function is intended to be used to locate/include template files, not functional files.

Just use include() and/or require() to include functional files in functions.php.

share|improve this answer

If and only if you are looking for a way to make your shortcode-functions.php file overrideable by child themes I'd suggest get_template_part, like this:

get_template_part('inc/shortcode-functions');

Notice that there is no .php at the end. That will load your file, whereas locate_template will fail. (I just tested it.) The difference between the two is that get_template_part does a little bit more work constructing file paths.

If you aren't trying to make it overrideable by a child theme, just use include.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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