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

Google Map iframe in a tab issue

You are using iframe in tab structure.So, 1) When page loads fully, the iframe in itenary tab has display none. so it is not loading the zoomed map properly. 2) When you switch to itenary tab before loading completes, iframe is display block i.e visible so it loads the url/map properly. So for this what … Read more

Help with AJAX front end comment moderation

Seems to me that the only problem is that you put the full approve url in the link, in this ways when you click the link you trigger the ajax and open the page url in the link. To be more clear your link is something like: <a class=”p3-comment-moderation” href=”https://wordpress.stackexchange.com/questions/128383/admin-ajax.php?action=p3_comment_approve&comment_id=123&nonce=xxxxx” data-comment_id=”123″ data-nonce=”xxxxx”>Approve</a> thanks to the … Read more

Add scripts on custom post add/edit pages Not Working

There are a few things you’ll want to do to make you include work and in generally better. Here is the complete code: function my_theme_enqueue_admin_scripts() { $screen = get_current_screen(); // This is how we will check what page we are on if ( in_array( $screen->id, array( ‘post’, ‘page’) ) && $screen->action == ‘add’ ) { … Read more

JavaScript added as link/stylesheet

wp_enqueue_script is for… scripts. You want wp_enqueue_style (and wp_register_style) for stylesheets. Also note that you can enqueue as many things as you’d like in a single function, no need to create a separate function for each. You can also pass all the same arguments to enqueue as you do to register, no need to register … Read more

Populating content dynamically via AJAX and Advanced Custom Fields [closed]

Here is what I ended up doing based on @gdaniel’s suggestion: AJAX call: $(‘.btn’).click(function() { $.ajax({ url:”<?php bloginfo(‘template_directory’); ?>/inc/galleries.php”, type: ‘POST’, data: {postID: ‘<?=$post->ID;?>’, galleryCategory: $(this).attr(“data-content”)}, success: function(resp) { $(‘#photos’).append(resp); } }); }); And here is my PHP file: <?php require(‘../../../../wp-load.php’); $postid = $_POST[‘postID’]; $galcat = $_POST[‘galleryCategory’]; ?> <div class=”photos” id=”$galcat”> <h1><?php echo $galcat; ?> … Read more

Call javascript function when category was added via ajax

Recently, I just have the same problem and got the solution. use ajaxSuccess event since we need to reset input when ajax is completed. filter the settings data for specific action and screen. Code: $(document).ajaxSuccess(function(e, request, settings){ var object = $.deparam(settings.data); if(object.action === ‘add-tag’ && object.screen === ‘edit-category’ && object.taxonomy === ‘category’){ //DO RESET Your … Read more