WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For a project, i've to improve SEO perf and one of this optimization is to load the sidebar with an ajax request.

I've looking for this solution through the documentation, source code, plugins repository without success.

So i need your help and advices. Is it possible to do this ? If yes, what is the best way ?


share|improve this question
up vote 1 down vote accepted

I didn't test anything, but I imagine it would be something like this:

As you must include a sidebar.php, just include an empty sidebar.php, and leave the real one to the sidebar-ajax.php, for example.

To call the sidebar:

<?php get_template_part('sidebar'); ?>

And it should be something like this:

<div id="sidebar"></div>

In your functions.php:

add_action('wp_enqueue_scripts', 'theme_enqueue_scripts');
function theme_enqueue_scripts() {
    /* load your js file in footer */
    wp_enqueue_script('theme-script', get_stylesheet_directory_uri() . '/your-js-file.js', false, false, true);

add_action('wp_ajax_get_ajax_sidebar', 'check_ajax');
add_action('wp_ajax_nopriv_get_ajax_sidebar', 'check_ajax');
function check_ajax() {

And in your-js-file.js:

    type: 'POST',
    url: location.href,
    data: { get_ajax_sidebar: 1 },
    success: function(data){
share|improve this answer
Sorry for belayted answer but your solution works fine. Thanks a lot. – ptiswitz Oct 17 '12 at 9:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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