Search code examples
phpwordpressshortcode

WordPress wrap div inside echo shortcode php


I'm trying to wrap a div using a shortcode that I'm calling from within my themes template.

So far I have this:

<?php echo do_shortcode('[tooltip content="Delete" url=""]'.<div class="delete-button-comments"><?php if ( bp_activity_user_can_delete() ) bp_activity_delete_link(); ?></div>.'[/tooltip]'); ?>

but I'm getting a syntax error (which I know why) but if I delimit the periods and apostrophes nothing happens at all.

So basically I would like to wrap the tooltips shortcode around the div that displays the icon that the div displays.


Solution

  • bp_activity_delete_link echoes the link, you should use bp_get_activity_delete_link() to return the value. Not exactly sure what you're trying to do, maybe something like:

    <?php
        $link = ( bp_activity_user_can_delete() ) ? '<div class="delete-button-comments">' . bp_get_activity_delete_link() . '</div>' : '';
        echo do_shortcode('[tooltip content="Delete" url=""]' . $link . '[/tooltip]');
    ?>