I am using wordpress functions in a custom php file including wp-load.php, run from browser it is fine, but run from command line with php /path/.php wp-load.php causes problems:

Warning: Cannot modify header information - headers already sent in /../wp-includes/ms-settings.php on line 162

code example to reproduce:

echo 'something';
require "/../wp-load.php";
  • Please edit your question to include the code you're trying to debug. – Pat J Jun 30 '15 at 15:36
  • Why are you trying to include wp-load.php directly? – sakibmoon Jun 30 '15 at 16:22
  • If you echo, you send headers, so you can not send them again or modified them. This is a pure PHP related problem not specifically related with WordPress. – cybmeta Jul 1 '15 at 7:07

WordPress has a command line library called WP-CLI. You can extend it to create your own commands. I would recommend this for any work on the command line.


I resolved this by using another php file to use from the command line with just a line like this:

file_get_contents('url to file I want to run');

the problem with using wordpress function in files outside of wordpress is that wordpress is bound to its installation so you gotta run it from an url belonging to the wordpress setup I think

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.