I'm coding a plugin. One particular file of this plugin is supposed to pull data from the plugin's custom DB table, and output it with minimal processing as raw XML.

The problem is, to get the WPDB class to work when the file was opened directly, I had to add a require to wp-blog-header.php. This worked great BUT it turns out that including the file outputs the tags < html>, < head>, and < body>, which kinda screws up certain parts of the XML.

Is there any way I can [A] Suppress the tag-spitting behavior of wp-blog-header.php? [B] Get WPDB working in some other way?

Or should I just not use WPDB for DB access in this file in the plugin?

EDIT: False alarm. Firefox was adding the tags at the user's end, not Wordpress. Sorry for raising a big stink.

1 Answer 1


Include wp-load.php, not wp-blog-header.php. Better yet, hook onto the execution of a standard WordPress request and die early.

isset( $_GET['my_conditional_check'] ) && add_action( 'plugins_loaded', 'my_xml_output' );
function my_xml_output()
    // do my stuff

This'll run WordPress, then my_xml_output(), then die before the request is actually parsed & the template is loaded/rendered:

  • 1
    Look into adding a feed with add_feed instead. Might fit the need better.
    – Otto
    Jul 31, 2012 at 23:17
  • Thanks for all your help. After the phantom < html> tags refused to go away, I finally got wireshark. Turns out they're being added by Firefox (at this end). On the bright side, your solution works better than mine did before.
    – SoItBegins
    Aug 1, 2012 at 0:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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