Hello friends, This is the very short tutorial about WordPress hacks which will let you know how to remove media button for custom post type. Are you using custom post type in your WordPress website and want to remove the Add Media button for that particularly post type not for the all post type, then keep your close attention in this tutorial.
Copy the below code snippet and paste it at the end of the functions.php file and save it. This will automatically remove the Add Media Button from that custom post type. It will also work with WordPress default post types like posts and pages.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
/** * Removing add media button from custom post type. */ function fm_remove_media_button() { global $current_screen; //use 'post', 'page' or 'custom-post-type-name' if( $current_screen->post_type == 'custom_post_type_slug' ) { remove_action('media_buttons', 'media_buttons'); } } add_action('admin_head','fm_remove_media_button'); |
Before implementing the below code, your post screen looks like:
If you want to allow users to access only own media files when they adding or updating the posts, pages, and custom post types. Use the below code in your functions.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
/** * Allow access to own content only */ function my_authored_content($query) { //get current user info to see if they are allowed to access ANY posts and pages $current_user = wp_get_current_user(); // set current user to $is_user $is_user = $current_user->user_login; //if is admin or 'is_user' does not equal #username if (!current_user_can('manage_options')){ //if in the admin panel if($query->is_admin) { global $user_ID; $query->set('author', $user_ID); } return $query; } return $query; } add_filter('pre_get_posts', 'my_authored_content'); |
After implemented the above code your post screen look like:
Do you like & share this article with your friends, and don’t forget to follow us on Facebook and Twitter to learn cool WordPress tutorials.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: wordpress tutorial, wordpress tutorial for beginner, wordpress tutorial for beginners, wordpress tutorials, wordpress tutorials for beginners, wordpress tutorils