Articles of include

The proper way to include/require PHP files in WordPress

I’m a new WordPress developer and recently I’ve been having problems (on multiple sites) with include_once and require_once for PHP files. If I include (get_theme_directory_uri() . ‘subdir/file’) the specified file gets included (or required, which leads to fatal errors) but if any WordPress functions are called within ‘file’ I get something similar to: ‘Call to […]

functions.php is being included twice, creating PHP fatal errors

I have a custom PHP script (which is importing WordPress via wp-load.php) that I’ve used successfully on many sites in the past, yet it’s misbehaving on one particular site seemingly after a couple of WordPress updates (currently version 4.7.1). The situation is this: The PHP script, requiring wp-load.php, is called via javascript to process form […]

locate_template function – File not getting included

$locate = locate_template( ‘widgets/the-post-widget.php’ ); I am using the above path and method to include a file in functions.php, but that is not happening. The file doesn’t seem to include. Am I doing a mistake?

Include Javascript as Plain (No file inclusion)

Is there a way to append Javascript to the body in the script tag without using a file? Normally you would do it with wp_enqueue_script(‘name’, ‘path/to/js/file’); Is there a way to include js in the script tag directly? Like: <script>My awesome code </script>

What's the best way to 'include' a file in WordPress?

Ive built simple web applications in the past using ‘include‘ functions and typically I’ve used this command: <?php include($_SERVER[“DOCUMENT_ROOT”] . “/data.php”); ?> This has worked great OUTSIDE of WordPress but my question is – can this be applied to a WordPress Environment? (I should add the reason I am doing this: it is because I […]

What's the correct way to include files in WordPress TwentyTen theme with it's own jquery scripts and css?

I want to include a slider in the default WordPress theme on the home page. I did manage to get the page to show using <?php if ( is_home() ) { include (‘slider.php’); } ?> but it doesn’t look like it’s loading the jquery script it needs or the style sheet. I know there’s a […]

Get current user data from external PHP page

I have a PHP page at the same level as the template/theme on WordPress. I need to be able to get the current logged in user details from this page. I have tried this: require_once( $_SERVER[‘DOCUMENT_ROOT’] . ‘/wp-load.php’ ); global $current_user; $current_user = wp_get_current_user(); var_dump( $current_user ); But it’s returning nothing. 0 as user_id and […]

PHP files included in functions.php don't seem to work

This is my first post on WordPress StackExchange, I’ll try to be precise. My question is: Is there anything in particular I should do to the files I’m including in my theme’s functions.php file? I’m creating a WordPress theme and my functions.php file is getting very big now. I managed to remove a lot of […]

Problems Including File

I read that if you create a php file and save it in the /wp-content/mu-plugins/ directory, WordPress will auto-load it. However, I haven’t yet figured it out. I don’t have a folder named mu-plugins; it’s just wp-content/plugins. I created a file at wp-content/plugins/echo-values.php, put a simple echo value in it and uploaded it, but I […]

How to include core files into plugin

I did some search about this but I don’t realize which is the correct way to include a wordpress core file into a plugin. I wish to include the wp-includes/ms-funcition.php file. For example if I use include_once(‘../../../wp-includes/ms-functions.php’) it wont load. Any suggestions? Thank you very much.