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?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.Sign up to join this community
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.
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
include_once, they are more expensive.
And shortcodes are not part of a good theme. :)