Loading multiple post content in FancyBox

You are using the selector ‘a[href=”#content”]’ in jQuery but the href attribute of the target links is #content<?php echo $i; ?>. Try removing <?php echo $i; ?> in the href attribute. If you need jQuery code recognise all <a> elements with href starting with the string “content” you can use the ^ modifier: jQuery(‘a[href^=”#content”]’). So … Read more

Using WP functions inside javascript

I found out about wp_localize_scripts here and it solves my issue: functions.php $var=get_current_user_id(); $params = array( ‘max’ => $var ); wp_localize_script( ‘myscript’, ‘MyScriptParams’, $params ); wp_enqueue_script(‘myscript’); and in the .js file I can retrieve this variable with MyScriptParams.max.

Replace link with form to pass variables to javascript / ajax

Worked out the answer with input from non WP-oriented forum and edited above to show. In short the variables were retrieved from WITHIN the js function using getElementByID and prevented error on non-action form with event.preventDefault(); like so: function glitch_player_display() { user_input = document.getElementById(“user_input”).value ? document.getElementById(“user_input”).value : 2; generated_var = document.getElementById(“generated_var”).value ? document.getElementById(“generated_var”).value : “Default_Var”; … Read more

prevent HTML output if custom field is empty [closed]

Just a simple php if to check the contents of the field before outputting markup. <?php if( $second_comment = get_field(‘second_content_block’) ){ ?> <div class=”page-content-text-additional”> <?php echo do_shortcode(“[vr_jsp] $second_comment [/vr_jsp]”); ?> </div> <?php } ?> You can eliminate the need for adding the class via js using the same method. Some friendly advice- spending a day … Read more

Notification when left menu bar is closed?

How to get a notification via Javascript when the left menu bar has been collapsed ? If you are taking about the admin menu bar and you want to get a notification when the that is closed and expanded, then watch thoroughly that, when admin menu bar is collapsed, a folded class is added to … Read more

Executing Javascript in Plugin

Based on what I can see, it looks like your calling the create_map function incorrectly. add_shortcode() takes 2 parameters, the name of the shortcode and the function that gets rendered when called. The array you are passing is how to call a method inside of a class. You’re basically saying call the create_map method from … Read more

admin-ajax.php (aborted) error when using jQuery.get

Are there any Console js errors? The admin-ajax.php is WordPress’s built in way of dealing with ajax so you should probably do something like this, assuming .get() would also work: $.post(ajaxurl, data, function(response) { alert(‘Got this from the server: ‘ + response); }); http://codex.wordpress.org/AJAX_in_Plugins

Accessing an API with jQuery and AJAX

There are a few things going on with your functions.php file that may be the issue. You should be using wp_enqueue_scripts action to enqueue your script. The first parameter of wp_localize_script() should match the id of the file you’ve enqueued. You also need to add a no_priv version for your Ajax call if it needs … Read more