WordPress Shortcode wrap around div

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>
</div>

I’ve also tried

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

Related posts

Leave a Reply

2 comments

  1. 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]');?>
    </div>
    
  2. 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:

    <?php
    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>
    </div>