1

I am wondering what is the right way to include additional php files for theme options, shortcodes, plugins and so on.

Both load_template and include will work, but what has better semantic value?

Thanks

2

load_template() is for cases where you need the following global variables in an included file:

$posts, 
$post, 
$wp_did_header, 
$wp_query, 
$wp_rewrite, 
$wpdb, 
$wp_version, 
$wp, 
$id, 
$comment, 
$user_ID

If you don’t need those, or if you use global in those files anyway, it isn’t needed.

locate_template() and get_template_part() are for cases when you want to allow child themes to replace the files with their own version. If you offer other ways to turn the loading off, it isn’t needed.

So, it depends on the context, on the position of your theme in the hierarchy (parent or child), and on the included code. You can use require if you want to. Avoid require_once and include_once, they are more expensive.

And shortcodes are not part of a good theme. :)

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.