Add JQuery As Code Snippet

Create js file and add it to your child theme script folder. Then just add code to functions.php, example if page is checout wp_enqueue that file. Example: https://sridharkatakam.com/how-to-load-woocommerce-css-and-js-only-on-shop-specific-pages-in-wordpress/

AJAX update fails for public/non-admin users

Alright, I came across another answer that’s finally solved this. I had a function (in functions.php) which revoked admin access to some user types I’d created with custom privileges – that was blocking non-admin access to admin-ajax.php. Old/new function below: Old function // Revoke dashboard access add_action(‘admin_init’, ‘restrict_access_admin_panel’); function restrict_access_admin_panel(){ global $current_user; get_currentuserinfo(); if ($current_user->user_level … Read more

Modifying child theme’s header

It’s good practice to use: the proper WordPress way of wp_enqueue_scripts to add your scripts and styles; the wp_head hook to add more code into your head section. Read more. Either you can use and place into your functions.php. Let me know if it’s what you were looking for.

Get user in rest API endpoint

Thanks to Jacob Peattie, I was able to solve this issue. You have to include a nonce from the WordPress Javascript API in your REST API requests if you wish to use information about the current user. From the WordPress documentation: If no nonce is provided the API will set the current user to 0, … Read more

Where is the Javascript attribute window._wpCustomHeaderSettings defined?

It’s defined via wp_localize_script() that’s called by the_custom_header_markup(): wp_localize_script( ‘wp-custom-header’, ‘_wpCustomHeaderSettings’, get_header_video_settings() ); So if you want to override the values/settings using JavaScript, then you can hook to wp_print_footer_scripts and add your script like so: add_action( ‘wp_print_footer_scripts’, function(){ if ( wp_script_is( ‘wp-custom-header’ ) ) : ?> <script> if ( window._wpCustomHeaderSettings ) { _wpCustomHeaderSettings.minHeight = 0; … Read more

Ajax Comment Upvotes – Votes don’t always register

Please try this and inform me what you got in the console. and sure console.log the type add_action( ‘wp_ajax_comment_meta_update_vote’, ‘comment_meta_update_vote’ ); function comment_meta_update_vote( ) { check_ajax_referer( ‘upvote_nonce’ ); $comment_id = $_POST[‘comment_id’]; $vote_score = get_comment_meta($comment_id , ‘vote’, true); $vote_score++; $updated = update_comment_meta($comment_id , ‘vote’, $vote_score ); if($updated){ $msg = ‘success’; }else{ $msg = ‘failed’; } $response … Read more

WordPress custom post type post item data – show/fetch only on click with Javascript dynamically?

I think you should be able to do this: HTML: <a class=”view_post_details” href=”#” post_id=”<?php the_ID(); ?>”>View Post Details</a> JS: $(“.view_post_detals”).click(function () { var id_post = $(this).attr(‘post_id’); $.ajax({ type: ‘POST’, url: ‘<?php echo admin_url(‘admin-ajax.php’); ?>’, data: { ‘post_id’: id_post, ‘action’: ‘f711_get_post_content’ //this is the name of the AJAX method called in WordPress }, success: function (result) … Read more