Including a file inside a subdirectory is the same as any other as long as you know the path to the file. Since it’s possible to move the ‘wp-content’ directory, don’t pass that part of the path to the require
statement; instead, use the WP_CONTENT_DIR
constant.
require_once WP_CONTENT_DIR . '/new-directory/my-file.php';
Also, you can leave out the parentheses since include
and require
are statements, not functions.
Related Posts:
- Include WP_Query in my own PHP file?
- Include a external PHP file into a WordPress Custom Template
- load/require specific php files for specific pages/templates/post types
- ob_get_clean returns empty string, ob_get_flush outputs string
- where to include a php file
- Include Class File in WordPress
- nowplaying.include.php Will Not Display Results
- integrating external php library into wordpress- the right way
- Change title and meta description in included page (not template)
- Can I change a variable in a content part while calling it?
- the_author() not working outside the loop
- How do I use the Simple HTML DOM Parser in plugin when other plugin already uses it?
- Put CSS inside a PHP file and include it the right way
- functions.php is being included twice, creating PHP fatal errors
- Custom theme: Alternatives to long list of ‘include’ in functions.php
- PHP help get_template_directory + PHP include
- code is skipping a div
- 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
- Correct and safe way to include php content in my page
- What is the proper way to include a PHP framework into my theme?
- php include not working in custom page
- Post’s ID pattern?
- Using WP functions such as the_title() in an included php file
- What’s the best way to include PHP code in pages?
- How to include custom PHP file both in header and footer files
- Include a file that has a function in it
- How do I call an external php non WordPress class into functions.php?
- require get_template_directory() . ‘path/to-my/file.php’ BREAKS customize > themes functionality
- Before & After Content – After Content directly below Before Content when using require_once
- loading a php file to a specific page id
- How do I fetch a data from an external database into my wordpress homepage
- How do I fetch a data from an external database into my wordpress homepage
- PHP get_category() function redeclared
- How do I / Is it possible to execute an external PHP file / function inside WordPress?
- Include a php file that is above WP installation hierarchically?
- How can I include a file related to blog URL? Nothing seems to work
- WordPress blog set up
- Shortcode not passing variable to included file
- php “use” not working in template [closed]
- How to include a php file in every post and page [duplicate]
- Shortcode to include PHP file, pass various parameters to include?
- wordpress.org disallowing my plugin becuase of loading core files in cron cpanel file
- Should I use include(_once) or require(_once) for loading php-file with customizer settings?
- Add a wp editor to custom plugin and save data
- How to display content from post_parent
- Second select list values are not saved after clicking update
- Use wc_enqueue_js only on specific pages – nested add_action
- Removing unnecessary wordpress files
- WordPress 3 – how are passwords stored and how do I compare to them?
- Use is_product_category() properly
- Double or Single Quotes in WordPress Content Conflicting With HTML
- How can i display post loop in table format?
- list posts and wrap them alphabetically A-Z
- Link to the parent post in attachment page
- WordPress 5 WP REST routes – No errors
- Using fwrite() and “a” appends multiple times instead of once
- Selectbox in admin panel function linking to CSS
- wordpress allow user to edit user profile with custom fields
- Making BuddyPress Activity Stream (Post Type) Featured Images Clickable [closed]
- WordPress admin dashboard missing icons
- Which field should I edit to make the checkbox marked by default?
- Add filter when image is uploaded?
- Keyword checking in Gravity Forms
- Get URL Parameters from referer
- Adding logo to WordPress header
- add_filter only for front office
- WordPress and MySQL: trying to print data using PHP from user_meta custom field data
- Form Submission Not Working In Custom Theme
- Concatenate Custom Field Value & HTML Value
- How do I properly code my footer? See example
- Use of IF statement in Header file
- Advanced Query posts
- Triggering a timewall after X days
- How to preload header logo image in WordPress? like what’s the code and where do I put it?
- echo cutom css code to WordPress page template file ? is this safe?
- PHP `iconv` not working inside a WordPress site
- How to make a “page-option” in WordPress
- Replacing entire tag with shortcode – JavaScript [duplicate]
- How do I visualize the author’s post from the front end?
- Query to show average # of months all accounts with specific role have been active
- Use PHP to inject HTML into before page renders?
- Query doesn’t display text data with apostrophes
- WooCommerce Custom Tab with ACF Repeater Field
- My WP Website Shows HTTP ERROR 500
- soap request in wordpress for a fedex pickup request [closed]
- Dynamically Create Posts Via XML File
- pages disable after wordpress update
- Create server side text from wordpress page
- How to set a cookie based on a page Get variable?
- Editing the contents of just one div on a page from wordpress
- How to change the menu color
- Display latest 5 posts on homepage
- Save Edit button then disabled readonly metabox
- Embed PHP script into WP – what is the best way
- Using global variables
- How can I remove paginated SEO titles from my WordPress site?
- What is wrong with my sorting logic?
- Count the number of matching post names in foreach loop
- what to do after instlling cyberpanel on VPS