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]');?>
  • Could you elaborate on why you need to do this? – Frank Martin Jun 29 '11 at 16:16

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]');?>
  • 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>
  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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