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

  • Home
  • SEARCH
  • 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 8817687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:54:38+00:00 2026-06-14T04:54:38+00:00

I have a functional wordpress theme that loads content via ajax. One issue that

  • 0

I have a functional wordpress theme that loads content via ajax. One issue that I’m having though is that when pages are loaded directly the ajax script no longer works. For example the link structure works as follows, while on http://www.example.com and the about page link is clicked then the link becomes http://www.example.com/#/about. But when I directly load the standalone page http://www.example.com/about, the other links clicked from this page turn into http://www.example.com/about/#/otherlinks. I modified the code a little bit from this tutuorial http://www.deluxeblogtips.com/2010/05/how-to-ajaxify-wordpress-theme.html. Here is my code. Thanks for the help.

jQuery(document).ready(function($) {
var $mainContent = $("#container"),
    siteUrl = "http://" + top.location.host.toString(),
    url = ''; 

$(document).delegate("a[href^='"+siteUrl+"']:not([href*=/wp-admin/]):not([href*=/wp-login.php]):not([href$=/feed/]))", "click", function() {
    location.hash = this.pathname;
    return false;
}); 

$(window).bind('hashchange', function(){
    url = window.location.hash.substring(1); 

    if (!url) {
        return;
    } 

url = url + " #ajaxContent"; 

    $mainContent.fadeOut(function() {
        $mainContent.load(url,function(){
            $mainContent.fadeIn();
        });        
      });
    });

  $(window).trigger('hashchange');

});
  • 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-14T04:54:39+00:00Added an answer on June 14, 2026 at 4:54 am

    The problem you are expressing is not easily solved. There are multiple factors at stake but it boils down to this :

    • Any changes to a URL will trigger a page reload
    • Only exception is if only the hash part of the URL changes

    As you can tell there is no hash part in the URL http://www.example.com/about/. Consequently, this part cannot be changed by your script, or else it will trigger page reload.
    Knowing about that fact, your script will only change the URL by adding a new hash part or modifying the existing one, while leaving alone the “pathname” part of the URL. And so you get URLs like http://www.example.com/about/#/otherlinks.

    Now, from my point of view there are two ways to solve your problem.

    First, there is an API that can modify the whole URL pathame without reload, but it’s not available everywhere. Using this solution and falling back to classical page reload for older browser is the cleaner method.

    Else, you can force the page reload just once to reset the URL to http://www.example.com/ and start off from a good basis. Here is the code to do so :

    $(document).delegate("a[href^='"+siteUrl+"']:not([href*=/wp-admin/]):not([href*=/wp-login.php]):not([href$=/feed/]))", "click", function() {
        location = location.assign('#' + this.pathname);
        return false;
    }); 
    

    It should be noted that this script won’t work if your site is not at the root of the pathname. So for it to work for http://www.example.com/mysite/, you will need changes in the regex.

    Please let me know how it went.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WordPress plugin that loads pages with AJAX and to ensure compatibility
I have developed a Wordpress site that loads pages dynamically using the .load function.
this is function.php of a wordpress theme that NOD32 says this code have a
I creating a WordPress theme, and I have implement a function that allowing the
I have a wordpress theme that i'm trying to add some minor security to
I have plugin by WPMU that creates a membership system for your wordpress theme.
I'm working on a wordpress project and having a frustrating issue with ajax. I'm
I have a file that resides in: /Library/WebServer/Documents/wordpress/wp-content/themes/directorypress/sidebar-left-big.php I have another file in sub
I'm coding a Wordpress theme and I'm having an issue displaying 5 dynamic post
So I'm using the History.js plugin to load pages in my Wordpress theme via

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.