WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When a file with the .xml extension has been uploaded on my blog (via the Add Media uploader) I would like to automatically replace some attributes.

For example, if I upload a file with this content:

<content creator="foo"></content>

I would like that Wordpress modifies it automatically in:

<content creator="bar"></content>

What hook should I use and how?

share|improve this question
up vote 1 down vote accepted

You can do this using the wp_handle_upload hook:


Create a function and add it to this hook so it runs last, it will be passed an array. The array contains the location of the newly uploaded file:

function wpse_66775_handle_upload($args){
    $filename = $args['file'];
    $type = $args['type'];
    // test if it's an XML file and do some work on it
    if(the file is an xml file){
    return $args;

function super_magic_xml_file_modifier($filename){
    // General PHP/XML stuff that doesn't belong on WPSE

Modifying the XML file etc, is another task that is not within the scope of this site.

share|improve this answer
A little note that may be useful to those who read this post in the future: the wpse_66775_handle_uploadfunction must return $args. – User Oct 1 '12 at 13:43

Your Answer


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.