Passing JSON-encoded HTML from WordPress to JavaScript

While it’s not exact answer to your precise question, I agree with method suggest in comment. Just skip trying to stuff data into single dimension and make use of l10n_print_after argument instead. See pass object/JSON to wp_localize_script question and answer there.

Add a Fancybox automatically to post type “post” images

Here is the code i use in my site, which loads all images under an anchor tag to fancybox add_action(‘wp_footer’,’auto_fancy_box’); function auto_fancy_box(){ if (!is_single() && !is_page()) return; ?> <SCRIPT TYPE=”text/javascript”> jQuery(document).ready(function(){ jQuery(“.post_content”).find(“a:has(img)”).addClass(‘group’); jQuery(“.post_content”).find(“a:has(img)”).attr(‘rel’,’group1′); jQuery(“a.group”).fancybox({‘transitionIn’:’elastic’,’transitionOut’:’elastic’,’speedIn’:600,’speedOut’:200,’overlayShow’:false}); }); </SCRIPT> <?php } just change the .post_content to your post content container jQuery selector.

wp_verify_nonce not working

I don’t know I just submitted the ticket on track. I was using get_current_user_id() and it modifies the wp_create_nonce behavior. Sinces wp_create_nonce uses wp_get_current_user() I think there is the problem.

Ajax comments not working

<div> <div class=”CommentList”></div> <form action=”” class=”commentForm”> <textarea name=”comment”></textarea> <input type=”button” value=”Comment” class=”btnComment” /> </form> </div> <div> <div class=”CommentList”></div> <form action=”” class=”commentForm”> <textarea name=”comment”></textarea> <input type=”button” value=”Comment” class=”btnComment” /> </form> </div> <script type=”text/javascript”> $(document).ready(function () { $(‘.commentForm’).each(function () { $(this).prepend(‘<div class=”comment-status”></div>’); }); $(‘.commentForm’).find(‘.btnComment:button:not(.Process)’).live(‘click’, function () { $(this).addClass(‘Process’).attr(‘disabled’, true); var commentFormObj = $(this).parents(‘form.commentForm’); commentFormObj.find(‘textarea[name=comment]’).val(”); var statusDivObj = … Read more

Stumped – Ajax Response Returns 0

Debug it logically. This code works. I just tested it. This in a theme (I put it in header.php for testing): jQuery(document).ready(function() { var lanid = ‘demo’; var ajaxurl=”<?php echo admin_url(“admin-ajax.php”, null); ?>”; data = { action: “get_ldapattr”, lanid: lanid}; jQuery.ajax({ url: ajaxurl, data: data, dataType: ‘json’, type: ‘post’, success: function(response) { console.log(response); } }); … Read more