Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Currently I have a short that embeds a div into the the_content. This works fine like thus:

[shortcode param=1 param=2]

This returns a message at the end of the post, but within the current article, however instead of being:

<article>
  <div>
</article>

I'm looking to produce:

<article>
</article>
<div>

Is this possible, and what functions do I need use? I've already tried using add_filter and apply_filter but they went into a infinite loop instead of:

return $message.

Thanks.

share|improve this question
    
Your shortcode already appears to do what the title of the question is asking. Nor is the title describing what you're actually asking. Please ammend the title –  Tom J Nowell Aug 26 '12 at 17:45
    
Thanks for accepting, I hope you manage to implement what you need –  Tom J Nowell Aug 26 '12 at 20:48
add comment

1 Answer

up vote 2 down vote accepted

What your asking for can't be done using shortcodes. <article> isn't a part of the content, its part of the theme and it 'contains' the content. Thus shortcodes cannot modify it or move those tags around. Shortcodes by definition are part of the content, so anything they add on the end is also a part of the content.

Instead you will need to modify your theme to add the extra elements somewhere else. How this is done is beyond the scope of this question/answer, but I advise using post meta ( and metaboxes to provide a UI )

To demonstrate the irrationality of what you're requesting:

<article>
  <?php the_content(); ?>
</article>
<!-- you want the_content() to magically reach over here via a shortcode and do something --!>

Instead, something along these lines:

<article>
  <?php the_content(); ?>
</article>
<?php
$meta = get_post_meta($post->ID,'_dothing',true);
if($meta == true){
    $param1 = get_post_meta($post->ID,'_dothing_param1',true);
    $param2= get_post_meta($post->ID,'_dothing_param2',true);
    that_shortcode_thing_you_wanted($param1,$param2);
}
?>
share|improve this answer
add comment

Your Answer

 
discard

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.