0

I'm currently creating a bunch of (empty) pages and performing conditionals such as is_page('Blabla') on it, which increases my page.php significantly. I'm already using require_once for different content, but is there a cleaner way of doing this?

2 Answers 2

2

Wordpress has a function for including template parts, which you can use for that purpose : get_template_part

You can also use include(TEMPLATEPATH . '/includes/myfunction.php');

0

I have answered this question here https://wordpress.stackexchange.com/a/412301/45516

But I will summarize my answer here also.

There are three ways to include a file.

  1. Enforce use of parent theme's directory:
require get_template_directory() . '/vendor/autoload.php';
  1. Permit use of parent theme of child theme's directory if there is one:
require get_stylesheet_directory() . '/vendor/autoload.php';
  1. Use within a plugin:
require __DIR__ . '/vendor/autoload.php';

The plugin_dir_path() offer no specific benefit over these methods.

See https://developer.wordpress.org/reference/functions/plugin_dir_path/ for more details.

Avoid include, use require because a missing file won't stay unnoticed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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