AJAX post into pop-up div

Your code is not clear as it is out of context but it looks to me like you are loading your posts pages over AJAX through their normal URLs– URLs like http://example.com/this-is-a-post/ or http://example.com/2012/12/01/this-is-a-post/. The drawback to doing that you are loading the entire WordPress and theme framework into your popup, which may be much more overhead than you need and more content than you want to display. You’ll get the page header and footer, the sidebars, etc. If that is what you want, fine… except for the fact that you are probably generating very broken HTML. From the jQuery Docs for .load:

Load data from the server and place the returned HTML into the matched
element.

So, if you are doing what I think you are doing, you are nesting a complete webpage– from <html> to </html> inside another one, which is wrong.

Ultimately, you would be better just grabbing the post(s), which is slightly more complicated but more efficient. If you were to do that, you’d want to use admin-ajax.php.

Some of the “complexity” of the other wpse thread you referenced is the enqueueing of the scripts. I don’t know how you are doing that but you should be doing it as in the accepted answer of that thread, by using wp_enqueue_script

Leave a Comment