WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

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.

share|improve this question
Have you worked with AJAX before? – Brian Fegter Feb 1 '12 at 11:58
nope not even once – phantom.omaga Feb 1 '12 at 12:02
It's actually pretty easy. Follow the link in my answer below and they give you a working example of this. – Brian Fegter Feb 1 '12 at 12:15
up vote 1 down vote accepted

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. :)

share|improve this answer

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.