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?


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.


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:


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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