Skip to content

Instantly share code, notes, and snippets.

@ravinsharma12345
Created December 13, 2013 06:33
Show Gist options
  • Save ravinsharma12345/7940568 to your computer and use it in GitHub Desktop.
Save ravinsharma12345/7940568 to your computer and use it in GitHub Desktop.
<?php
/**
* Callback for WordPress 'post_edit_form_tag' action.
*
* Append enctype - multipart/form-data and encoding - multipart/form-data
* to allow image uploads for post type 'post'
*
* @global type $post
* @return type
*/
function my_post_edit_form_tag(){
global $post;
// if invalid $post object, return
if(!$post)
return;
// get the current post type
$post_type = get_post_type($post->ID);
// if post type is not 'post', return
if('post' != $post_type)
return;
// append our form attributes
printf(' enctype="multipart/form-data" encoding="multipart/form-data" ');
}
add_action('post_edit_form_tag', 'my_post_edit_form_tag');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment