Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • in reply to: Metabox/Post Type Only Specific Assets #6479
    dukecreative
    Member

    Hi Jason,

    Thanks for your reply, I ended up using the following to restrict loading to the post type:

    
    global $pagenow;
    
    if ( 'post.php' === $pagenow && isset($_GET['post']) && 'your_post_type' === get_post_type( $_GET['post'] ) ){
    
    add_filter('piklist_assets', 'plugin_assets');
    function plugin_assets($assets)
    {
        array_push($assets['scripts'], array(
            'handle'    => 'plugin-scripts',
            'src'       => plugins_url('/your_plugin_name/parts/js/scripts.js'),
            'ver'       => '1.0',
            'deps'      => 'jquery',
            'enqueue'   => true,
            'in_footer' => true,
            'admin'     => true,
            'front'     => false
        ));
    
        return $assets;
    }
    }
    

    This ensures assets are loaded only where required and not globally.

Viewing 1 post (of 1 total)