-1

I am using the plugin Ajax Load More - Infinite Scroll together with Masonry grid. For example, my index.php includes the following:

<?php echo do_shortcode(‘[ajax_load_more post_type=”post” category=”‘ . $wp_query->query_vars[‘category_name’] . ‘” tag=”‘ . $wp_query->query_vars[‘tag’] . ‘” offset=”8″ posts_per_page=”10″ pause=”true” scroll=”false” button_label=”Show me more posts.” transition_container=”false” transition=”none”]’); ?>

All seems to work fine, but when moved the blog behind a reverse-proxy on the staging area, I have issues with calling the admin-ajax.php from wp-admin (either 403 or very long loading time for the ALM articles) as it is not allowed through the reverse proxy rules in Apache. From the source page, I can see, in fact, the following:

/* <![CDATA[ */
var alm_localize = {“ajaxurl”:”http:\/\/siteurl\/test\/wp-admin\/admin-ajax.php”,”alm_nonce”:”0dge8w13b3″,”pluginurl”:”http:\/\/homeurl\/test\/wp-content\/plugins\/ajax-load-more”,”scrolltop”:”false”};
/* ]]> */

where the ajaxurl is still where my WP core installation files reside, while the pluginurl is correctly my homeurl (that accessible to the users).

I have the following question:

  • Can you bypass the loading of admin-ajax.php directly from wp-admin and rather making it load on the front page? I have found references of use of wp_enqueue_script() and from:

https://codex.wordpress.org/AJAX_in_Plugins

However, I am not sure how this can be used with the Ajax Load More - Infinite Scroll plugin and. Can you help?

  • Is it secure to include an Apache rule to give access to that particular script?

Thank you for your help,

N.

EDIT1:

So, I have come up with this:

//localize the admin-ajax.php
 $localiser = array(
    'ajaxurl' => admin_url('wp-admin/admin-ajax.php' ),
  );
  wp_localize_script( "ajax-load-more", "alm_localize", $localiser );

  //Define plugin constant
  define( 'AJAX_PLUGIN', dirname( __FILE__ ) );

  //Register script
  wp_register_script( 'ajax-load-more', 'AJAX_PLUGIN' . '/core/js/ajax-load-more.js');

However, not only it has no effect on the actual URL for the admin-ajax.php (that still refers to the siteurl, rather than the current home_url), but has changed the script location:

<script type='text/javascript' src='http:\/\/siteurl\/test\AJAX_PLUGIN/core/js/ajax-load-more.js?ver=4.6.1'></script>

The siteurl is reversed proxy in Apache, can you please tell me whether what I am trying to achieve is even possible? How can have admin-ajax.php loaded on the front end? Can I move it to my theme folder? Do I have to modify the 3rd party plugin for that to work?

Thank you!

EDIT2:

By inspecting through the web developer tools I can see this error in the console:

http://siteurl/test/wp-admin/admin-ajax.php?action=alm_query…anonical_url=http://homeurl/test/ 403 (Forbidden)

What does it actually mean? What is alm_query…anonical_url?

2
  • Why the downvote?
    – panza
    Commented Jan 22, 2017 at 11:05
  • If you dont mind please share URL where you are getting the console error Commented Jan 24, 2017 at 8:28

1 Answer 1

0

You don't need to specify wp-admin in the path to the admin-ajax.php file. You can simply use array( 'ajaxurl' => admin_url( 'admin-ajax.php' ).

$localiser = array(
    'ajaxurl' => admin_url('admin-ajax.php' ),
  );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.