Title: Plugin does not work with directive include or require
Last modified: April 12, 2025

---

# Plugin does not work with directive include or require

 *  [daro2013](https://wordpress.org/support/users/daro2013/)
 * (@daro2013)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/plugin-does-not-work-with-directive-include-or-require/)
 * Is there any way of making this plugin work with the following directives:
 * include
 * require
 * Many thanks in advance.
 * Daro

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [anjalixyzscripts](https://wordpress.org/support/users/anjali94/)
 * (@anjali94)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/plugin-does-not-work-with-directive-include-or-require/#post-18416655)
 * 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.
 *  Thread Starter [daro2013](https://wordpress.org/support/users/daro2013/)
 * (@daro2013)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/plugin-does-not-work-with-directive-include-or-require/#post-18416684)
 * 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
 *  [anjalixyzscripts](https://wordpress.org/support/users/anjali94/)
 * (@anjali94)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/plugin-does-not-work-with-directive-include-or-require/#post-18416701)
 * 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
 *  Thread Starter [daro2013](https://wordpress.org/support/users/daro2013/)
 * (@daro2013)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/plugin-does-not-work-with-directive-include-or-require/#post-18417122)
 * 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?
 *  Thread Starter [daro2013](https://wordpress.org/support/users/daro2013/)
 * (@daro2013)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/plugin-does-not-work-with-directive-include-or-require/#post-18417184)
 * Update: It is working now. It is a great plugin; I ll give a 5 stars shortly.
 * Many thanks

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Plugin does not work with directive include or require’ is closed to 
new replies.

 * ![](https://ps.w.org/insert-php-code-snippet/assets/icon-128x128.png?rev=1800967)
 * [Insert PHP Code Snippet](https://wordpress.org/plugins/insert-php-code-snippet/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/insert-php-code-snippet/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/insert-php-code-snippet/)
 * [Active Topics](https://wordpress.org/support/plugin/insert-php-code-snippet/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/insert-php-code-snippet/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/insert-php-code-snippet/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [daro2013](https://wordpress.org/support/users/daro2013/)
 * Last activity: [1 year, 1 month ago](https://wordpress.org/support/topic/plugin-does-not-work-with-directive-include-or-require/#post-18417184)
 * Status: not resolved