Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8986733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:37:15+00:00 2026-06-15T21:37:15+00:00

I’ve been recently playing with implementing AJAX into WordPress. I know there is many

  • 0

I’ve been recently playing with implementing AJAX into WordPress. I know there is many plugins available but I wanted to make it on my own.

In articles regarding to AJAXified WordPress most people recommend using admin-ajax.php to process AJAX requests. My first idea how to make it was to simply create custom get_header() and get_footer()

1st way

// Boolean function ?ajax=true
function is_ajax () {
  if($_REQUEST['ajax']) {
    return true;
  } else {
    return false;
  }
}

function ajax_get_header () {
  if(is_ajax()) {
    get_header('ajax'); 
    /* Insert header-ajax.php which
    includes only google analytics tracking code and some minor stuff */
    return true;
  } else {
    get_header();  
    // Standard header
    return true;
  }
}

/* Function ajax_get_footer() pretty much the same */

Then, page templates would look like

<?php ajax_get_header(); ?>

<!-- Content -->

<?php ajax_get_footer(); ?>

And making ajax calls the standard way, of course.
This method looks for me simple and clean.
On the other hand, many people recommend using built-in function, by creating a hook to catch AJAX calls.

2nd way

function process_ajax(){
  /* Show the page or whatever */
}
add_action('wp_ajax_nopriv_ajax', 'process_ajax');
add_action('wp_ajax_ajax', 'process_ajax');

And pointing AJAX calls to admin-ajax.php

Which one to use?

I have tried both these methods and discovered that the first way is loading remarkably faster then the latter one. In same conditions the 1st way (ajax_get_header) took approximately 400ms to load a page (almost no content) and the 2nd way (admin-ajax.php) about 800ms. I dont know why, both ways load WP core and do thing almost the same.

So, I am asking you, is there a serious reason to make AJAX calls through admin-ajax.php? Is it nessesary? And why it takes more time to process a call through the recommended way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:37:17+00:00Added an answer on June 15, 2026 at 9:37 pm

    Your 1st way is always going to be faster than WordPress’s own ajax since admin-ajax.php takes care of lot of other things like core admin hooks and other function calls which in turn makes the whole ajax call pretty huge.

    in the first way, You are not bothering about anything else other than your own functions and output. That increases the performance.

    There is no hard and fast rule what to use, The first way you can do things faster but they won’t be hookable with wordpress’s core admin functions which may be a disadvantage for some purpose.

    See admin-ajax.php

    $core_actions_get = array(
    'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed-cache',
    'autocomplete-user', 'dashboard-widgets', 'logged-in',
    );
    
    $core_actions_post = array(
    'oembed-cache', 'image-editor', 'delete-comment', 'delete-tag', 'delete-link',
    'delete-meta', 'delete-post', 'trash-post', 'untrash-post', 'delete-page', 'dim-comment',
    'add-link-category', 'add-tag', 'get-tagcloud', 'get-comments', 'replyto-comment',
    'edit-comment', 'add-menu-item', 'add-meta', 'add-user', 'autosave', 'closed-postboxes',
    'hidden-columns', 'update-welcome-panel', 'menu-get-metabox', 'wp-link-ajax',
    'menu-locations-save', 'menu-quick-search', 'meta-box-order', 'get-permalink',
    'sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order',
    'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post',
    'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment',
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.