Reputation: 17487
I'm creating a custom WordPress theme and I'm trying to do so without using any plugins whatsoever. I enabled Featured Images for posts by adding the following to my theme's functions.php
:
add_theme_support('post-thumbnails', array('post'));
I added some custom admin settings pages for managing the clients' artwork related files, like icons and logos and whatnot. So, I also added the following to my theme's functions.php
in order to get the Media Uploader to work on these new settings pages:
wp_enqueue_style('media-editor');
wp_enqueue_media();
Unfortunately, for some reason, the wp_enqueue_media();
function call is breaking the Featured Image function in my admin's Edit Post page.
I am able to open the Media Browser, upload an image and select it, but clicking the Set Featured Image does nothing and throws no console errors.
Commenting out wp_enqueue_media()
fixes the Featured Image, but breaks the custom admin settings page.
The enqueue_media call was performed during the after_setup_theme
action. Am I doing something wrong? Is this a bug?
Is there a way to detect which custom admin page I am one, so I can only enable the media uploader on it?
WordPress Version 4.2.4
Upvotes: 0
Views: 717
Reputation: 4116
Here you go, this will enqueue media
when you are on custom page.
add_action( 'admin_enqueue_scripts', function( $hook )
{
/** @var \WP_Screen $screen */
$screen = get_current_screen();
//echo '<pre>';print_r($screen);echo '</pre>';
if ( 'your_custom_page.php' == $screen->base ) {
wp_enqueue_media();
} else return;
} );
Upvotes: 1