I have a shopping cart which uses AJAX to add/remove items to the cart from an <a> styled as a button which links to an action like /wp-admin/admin-ajax.php?action=shopping_cart&id=16&nonce=123456&type=add.

These links keep getting crawled by search engines - however, since the nonce is different each time, the list of crawl errors keeps growing.

What's the most effective method to prevent search engines from trying to follow the link? I understand that a simple nofollow may not be appropriate for internal links. Alternatively, I am misusing the <a> tag and would another element and a bit of jQuery to follow the admin-ajax.php link be better?


If an ajax call is indexed it compromises the whole purpose of the application. The cause here is that you are making your call using GET instead of POST as suggested: https://codex.wordpress.org/AJAX_in_Plugins

The right way should be along something like :

add_action( 'admin_footer', 'my_SHOP_javascript' ); // Write our JS below here

function my_SHOP_javascript() { ?>
    <script type="text/javascript" >
    jQuery(document).ready(function($) {

        var data = {
            'action': 'shopping_cart',
            'id': 16,
            'nonce': '12345',
            'type' : 'add'

        jQuery.post(ajaxurl, data, function(response) {
    </script> <?php
| improve this answer | |
  • The server returns a 403 if the nonce isn't valid so the ajax calls aren't getting indexed, but I'd still like a method to prevent them attempting to crawl. The ajax call is initiated by jQuery with the link as a fallback. – mistertaylor Jan 24 '17 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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