A script loaded within a function call will only work within the immediate scope of where require
or include
was used. So really only variables present when load_template()
is called will be accessible to the loaded script (unless you use global $myvar
of course).
The reason vars like $post
and $wp_query
are available to the script is because load_template()
globals them in before loading the script.
If you wanted to make sure your script can access certain vars, either global
them in or add them to the $wp_query->query_vars
array before loading (not recommended but depending on the task it might be the only feasible option), as those get extracted into the local scope before loading the script.
Related Posts:
- Serving precompressed content with Brotli on Apache
- How can I avoid code duplication for a blog with lots of source code?
- How to rename wp-includes folder?
- What’s the correct way to include files in WordPress TwentyTen theme with it’s own jquery scripts and css?
- ABSPATH not working! Any idea why?
- Get current user data from external PHP page
- External system integration with wordpress
- How to pass variables with get_template_part?
- Problems Including File
- How to include core files into plugin
- How to check if txt file exists inside template folder?
- What’s the best way to ‘include’ a file in WordPress?
- locate_template function – File not getting included
- Can not include file from plugin into theme
- Include tags from array, ignore the rest in get_the_tags
- PHP files included within functions.php don’t work from admin area
- Wp Enviroment problem with included file
- Having trouble linking to file using relative path
- How can I include an external file in a post or page?
- Including php file in directory above WordPress installation
- add_feed failed to open stream
- Load content From Include File within plugin
- including Zend Gdata library path error
- What about “inc” (include) files and Child Theming? Is it possible?
- Make changes in /includes/http.php update safe
- Need to override file included in parent theme
- Class works in Admin, not found on Front End
- if statement parent page for child pages
- add_action outside a plugin
- Add page as static html into another page
- Dynamically determine URI to scripts and styles included with a class which could be added from plugin/theme/child theme/mu plugin
- class not declared in scope – even though .h was included
- “Multiple definition”, “first defined here” errors
- Error “Unterminated conditional directive” in cross-referencing headers
- “Fatal error: Cannot redeclare function”
- Compiler error C4430: missing type specifier – int assumed [duplicate]
- Eclipse CDT: Symbol ‘cout’ could not be resolved
- get_template_directory_uri pointing to parent theme not child theme
- The proper way to include/require PHP files in WordPress
- How do I replace a function, declared inside a plugin’s class, in functions.php?
- Should we use get_template_part() in functions files instead of include_once?
- Order by & include array by specific post ids
- load/require specific php files for specific pages/templates/post types
- How can I include JavaScript that use jQuery on admin side
- ob_get_clean returns empty string, ob_get_flush outputs string
- Include files for a plugin not including
- Adding rich text editor to my plugin
- Include Javascript as Plain (No file inclusion)
- Including an External File in a Post (and Using Processed Paths)
- integrating external php library into wordpress- the right way
- How do I use the Simple HTML DOM Parser in plugin when other plugin already uses it?
- Should I use include or load_template for including shortcodes, plugins and so on?
- Looking for a way to include/embed text from a file on a page so that the short codes are processed
- functions.php is being included twice, creating PHP fatal errors
- How to display / include a specific jpg on a page
- Variable scope producing undefined variable notices in included files
- Use of Templates in a Plugin
- Automatically include all php files in a child theme directory
- Include comments form in plugin page
- WP Plugins – Use includes to display page content
- Why does abstracting html from plugin code result in loss of access to wordpress functions?
- PHP include is only working in certain places in my custom WP theme
- What is the proper way to include a PHP framework into my theme?
- Can I have an additional functions.php file in WordPress?
- Include file in plugin file
- What’s the best way to include PHP code in pages?
- confused about wp_list_pages() function – how to display selected top pages with all their subpages
- Use $variable from file1.php in file2.php (different file paths)
- Can I include a custom PHP function in a WordPress function?
- Issues with wp_enqueue_script and jquery-ui
- Trying to include files in plugin isn’t working
- Three step order form, how to go to next step
- Custom metabox not working
- How and when to include shortcode source files
- How do I call an external php non WordPress class into functions.php?
- Displaying page content from plugin, inside exising empty WP page
- Why should I use get_template_directory() when include files?
- WordPress functions.php conditional include another functions file
- FPDF for creating pdf diplomas
- get_template_part for template in subdirectory not working
- Before & After Content – After Content directly below Before Content when using require_once
- Multiple Taxonomy post query with exclusion
- Including admin-options.php file in Child Themes
- How to write wordpress plugins faster to load?
- Push Shortcode parameter to template
- sharing wp-include – wp-admin on same installation
- Include post on external custom site
- Pages included in another page and duplicate content issues for SEO
- Include a php file that is above WP installation hierarchically?
- How To Display Selected Terms For Custom Taxonomy?
- Include paths and functions for external scripts
- Want to include ad code after related post
- Custom meta box includes
- Including a PHP file via a function that is part of a plugin?
- strange parse error when including a loop template within another template
- After Migration, Warning: include_once() errors on all pages
- Shortcode return is printing a 1 afterward
- Shortcode to include PHP file, pass various parameters to include?
- Should I use include(_once) or require(_once) for loading php-file with customizer settings?
- WordPress Includes mejs 404 error