Hello Daro,
While the Insert PHP Code Snippet plugin technically allows include and require statements within your snippets, please note that these snippets are executed on the frontend, which may result in permission issues or “forbidden” errors when trying to load server-side files—especially if the included files are outside the theme directory or not publicly accessible.
If you still wish to use include or require, ensure that:
- The file paths are valid and within accessible directories (like your theme or a custom plugin).
- You’re not exposing sensitive server files.
- Proper checks (like
file_exists()) are added to prevent errors.
Let us know what you’re trying to include, and we’ll be happy to suggest a safer or alternative approach if needed.
Dear Sir,
Thank you for your support. I am struggling to use those directives in the plugin. Do I need to specify the full path of each URL or just part of it I have used in functions.php WP like:
include ‘php/number-of-posts-per-page.php’;
Note: php/ is the folder directly under Theme’s child. Which that part of URL, the plugin generates error. I have not tried a full URL yet.
Very appreciate your support.
Regards
D
In the context of the Insert PHP Code Snippet plugin, relative paths like:
include ‘php/number-of-posts-per-page.php’;
may not work reliably, because the snippet isn’t executed within the theme’s context like functions.php — especially when shown on the frontend.
Instead, you’ll need to use the full absolute path to the file.
Here’s how you can modify it safely using WordPress functions:
include get_stylesheet_directory() . ‘/php/number-of-posts-per-page.php’;
This ensures the file is loaded correctly from your child theme’s php/ folder, regardless of where the snippet is executed from.
Let us know if that works or if you need help
Dear Sir,
Thank you for great support.
I have tried the full path of URL you given, no more errors are generated. However, no posts are displayed at all.
If I copy & paste the whole files into the plugin widget, it works very well as expected
What could be an issue?
Update: It is working now. It is a great plugin; I ll give a 5 stars shortly.
Many thanks