What i want to do

I want some content (could be stored any where in a post or custom field) to load only when the user clicks for it to load. This content could be any thing (text,images,html etc) and this may be accomplished through any way (eg ajax, shortcode) i don't mind.


what i don't what to do is let the content be loaded before hand, be hidden and be displayed when demanded. It has to only load when its wanted or demanded.

  • Have you worked with AJAX before? Feb 1, 2012 at 11:58
  • nope not even once Feb 1, 2012 at 12:02
  • It's actually pretty easy. Follow the link in my answer below and they give you a working example of this. Feb 1, 2012 at 12:15

1 Answer 1


You should really take a look at the AJAX in Plugins article. It gives examples of how to setup AJAX the proper way in WordPress.

Here's the basic workflow of using AJAX in WordPress:

  1. Create an enqueue your custom JavaScript file that uses jQuery.post or jQuery.get or jQuery.ajax
  2. Create a callback for the wp_ajax action hook (learn the difference between normal and nopriv hooks)
  3. Within your callback function, you would create some logic that would echo whatever type of content you choose (make sure to exit or die() at the end of the callback)

It's best if you learn to fish on this one rather than someone doing the fishing for you. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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