Looking to update the ads via ajax, and stumbled onto the fact that the do_action will not work within an ajax call. Daniel reminded me that that is because the do_action() is dependent on the context (e.g. which post is loaded or the page that the ad is on). Would be great to be able to individually call (to update, or place the ad after the page has loaded) an ad code this way. Thoughts?
Rinat K 9:46 pm on November 12, 2012 Permalink |
The workaround woud be to make a separate template with an ad code call and then just fetch the page with AJAX.
jtsternberg 9:56 pm on November 12, 2012 Permalink |
But I would need the same conditionals to apply to this faux page that apply to the originating page. I.e. If I chose “is_home” as a conditional, and then reload the ads the way you’re suggesting, the same conditionals won’t apply (since a separate template is not, obviously, the home page). Am I missing something?
Rinat K 10:06 pm on November 12, 2012 Permalink
Well, nothing restricts you to add another conditional to home page ad tag that’ll match with this faux page. This approach is tested and works. The other way around would be calling the rendering method directly, but that probably wouldn’t work since there’s a bunch of hooks that are probably won’t get fired in AJAX context. Pull requests are always welcome 🙂