How to run a external JavaScript file on wp-admin if admin, and other if normal user?

You need to register/enqueue your admin scripts on admin_enqueue_scripts, not on wp_enqueue_scripts. wp_enqueue_scripts is a front end hook. It won’t run on the admin pages. Secondly, is_admin() just checks whether the page is an admin page, not whether the user is an administrator. To check whether the user is an administrator use: $current_user = wp_get_current_user(); … Read more

Get all of user’s custom post types in WP Admin for plugin

By passing the _builtin argument to get_post_types(), only WordPress default post types will be returned. Instead, just pass public as an arguement, Here’s an example of output on a development site with WooCommerce activated: var_dump(get_post_types([‘public’ => true])); //result array(4) { [“post”]=> string(4) “post” [“page”]=> string(4) “page” [“attachment”]=> string(10) “attachment” [“product”]=> string(7) “product” } With no … Read more

Can I individually style items in the backend widget list?

Just as @MarkKaplun mentioned in a comment, it’s possible with CSS. Also with Javascript. CSS Approach Let’s look at the Calendar widget, as an example. The id for the widget, in the available widgets list, is of the form: widget-{integer}_calendar-__i__ and in the sidebar it’s: widget-{integer}_calendar-{integer} If we want to display the calendar dashicon before … Read more

Adding a character counter to the excerpt metabox

Ok, so I didn’t like the way that was written, so i slightly rewrote it with different syntax, and more readable structure. <?php // Add Character Counter to the Excerpt Meta Box function excerpt_count_js(){ if (‘page’ != get_post_type()) { ?> <script> (function($){ $(document).ready(function(){ if ( $(‘#postexcerpt’).length ) { var maxChar = 128; $excerpt = $(‘#excerpt’); … Read more

JQuery not working on WordPress Admin page [closed]

There are this type of problem occure. In case- 1- jQuery function conflict to other jquery function. To remove this type of problem, define below script in wp-config.php file. define(‘CONCATENATE_SCRIPTS’, false); 2- jQuery liberaray file are not include in frontend. 3- Jquery same file defined more than one time. then this type of issue show … Read more

List User order by ID in Descending order (Backend)

I first thought that pre_user_query would be that hook for the job. But I think using the equivalent of pre_get_posts, which is pre_get_users, would be suitable here. You also said you wanted to run this in admin. So we will check that before running this. function my_custom_order_users_by_id( $query ) { //Check that we are in … Read more