WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

Is there a way to wrap a wordpress shortcode around a div in a template file? Here is my code:

<div id="subscription">
<?php do_shortcode('[subscribe]');?>
<p>This is subscription text</p>

I've also tried

<div id="subscription">
<?php do_shortcode('[subscribe]');?>
<p>This is subscription text</p>
<?php do_shortcode('[/subscribe]');?>
share|improve this question

migrated from stackoverflow.com Jun 30 '11 at 8:46

This question came from our site for professional and enthusiast programmers.

Could you elaborate on why you need to do this? – Frank Martin Jun 29 '11 at 16:16
up vote 0 down vote accepted

If by template file you mean a php file in the themes folder, you can call do_shortcode to have the shortcode processor do its magic on your div.

EDIT: not entirely sure I understand what you want, but you could try this:

<div id="subscription">
<?php do_shortcode('[subscribe]'.call_php_function().'[/subscribe]');?>
share|improve this answer
Yes thats exactly what I meant, and I've tried to insert it in the div but I dont think I'm doing it right. I'll past the code above. Thanks @Femi – Carlos Rios Jun 29 '11 at 16:06

I'm pretty sure the above code should be

<?php do_shortcode('[subscribe]<p>This is the subscription text</p>[/subscribe]'); ?>

Then you can use the content in the shortcode function like so:

function subscribe_shortcode($atts, $content = '', $code = NULL) {

return '<div id="whatever-etc">'.$content.'</div>';
add_shortcode('subscribe', 'subscribe_shortcode');


The above would output:

<div id="whatever-etc">
<p>This is the subscription text</p>
share|improve this answer
Thanks @Frank Martin! This is what I was also thinking, but the problem is the real code that Im using has some Php inside of my subscription div. is there a way that I could work with this? – Carlos Rios Jun 29 '11 at 16:25
This code is being used to hide and show content for premium users on a website. If they are logged in as a premium member it will show the content that is inside of the shortcode, otherwise it will say they can purchase it – Carlos Rios Jun 29 '11 at 16:26
If it's in the template file is there any need for the shortcode at all? Can't you just put a conditional statement around the content? – Frank Martin Jun 29 '11 at 16:29
That was my next option, but the plugin that I'm using to show and hide content targets what to hide with a shortcode. I know its pretty dumb but its normally used to hide content that is written within wordpress but for my case its different. Would you have an idea of how I could use a conditional for this? – Carlos Rios Jun 29 '11 at 16:34
To be honest I don't think I'm entirely clear on what you need to achieve. – Frank Martin Jun 29 '11 at 19:44

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.