maciejmatu
maciejmatu

Reputation: 612

Loading whole pages with ajax in wordpress

Im having a problem loading pages in wordpress with ajax. I have to make animated page transition, so i decided to use ajax and put page content into a div which i will animate into view. I created this logic, that works 50% of the time. There are generally a lot of weird bugs.

So my question did anyone create ajax page loader in wordpress? I read a bit about using ajax with wordpress, and that i had to use wordpress built in features, but I didn't get why is that. Also I don't know how to get the back button to work properly.

$( links ).click(function(e) {

    var link = $(this).get(0).href;
    $('body').append('<div class="contain-all"></div>');

    $('.contain-all').load(link);

    if(link!=window.location){
      window.history.pushState({path: link},'',link);
    }

    e.preventDefault();
});

Hope somebody has the anserws I need. :)

Upvotes: 3

Views: 1291

Answers (1)

maciejmatu
maciejmatu

Reputation: 612

Okay i read a bit about ajax in wordpress and loading pages, and you can achieve this by creating template parts which you will fetch by a function in wordpress functions.php, by calling it with ajax. It sounds complicated, (and it partly is), but you can read more about it here:

https://premium.wpmudev.org/blog/load-posts-ajax/

Also if anybody have questions they can ask them here, so everyone will have access to them.

Upvotes: 1

Related Questions