Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom page template creating an xml feed found on a WP page at http://example.com/xml/

I am trying to access this xml document via Google Maps but it appears I need the actual file name like example.com/xml/example.xml

How can I add a .xml file extension at the end of the link http://example.com/xml/ ?

EDIT: I am using a page template in my theme to display the output of XML. The XML part is probably irrelevant. What it comes down to I guess is how do I assign a specific file extension off of a page template such as /example.xml

share|improve this question
    
I'm not the one who gave you a down vote, but may I suggest that you elaborate a little more on your question. Which plugin (or method) creates the .xml? The more details, the more likely someone is to help you. –  Travis Pflanz Apr 24 '12 at 21:02
    
I am using a page template in my theme to display the output of XML. The XML part is probably irrelevant. What it comes down to I guess is how do I assign a specific file extension off of a page template such as /example.xml –  RonnieT Apr 24 '12 at 21:11
    
Might I suggest that you add this comment and the code to your original question. –  Travis Pflanz Apr 24 '12 at 21:13

1 Answer 1

Actually, the extension is irrelevant.

When your page is returned, WordPress is setting the content-type for the file in the headers as text/html; charset=UTF-8. This tells any consuming application that the content is HTML, not XML.

You need to force WordPress to send the appropriate headers when outputting the XML.

This content type is set by bloginfo('html_type') and is often copied into a <meta /> tag in your blog header as well. You can add a filter to hook in to this value:

add_filter( 'option_html_type', 'my_xml_override' );
function my_xml_override( $type ) {
    // First, check to make sure you're on the right page template:
    if ( /* On XML template */ ) {
        $type = 'text/xml';
    }

    return $type;
}

I leave detecting the page template as an excerise for you ... mostly because I don't have the time to test it for you. But if you look around, there are plenty of tutorials available.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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