• Resolved matreece

    (@matreece)


    Hi, I have some shortcode I’m trying to wrap around some additional php code. Basically I’ve downloaded a plugin that hides/reveals content which I wish to wrap around my comments box.

    The two codes I have is –

    <?php echo do_shortcode(‘[show-hide]’.$text_to_be_wrapped_in_shortcode.'[/show-hide]’); ?>

    I want to replace the ‘$text_to_be_wrapped_in_shortcode’ with the below:

    <?php if ( comments_open() || ‘0’ != get_comments_number() )
    comments_template(); ?>

    Any ideas and help appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Michael

    (@alchymyth)

    untested:

    <?php if ( comments_open() || '0' != get_comments_number() ) :
    ob_start();
    $comments_template();
    $comments_output = ob_get_contents();
    ob_end_clean();
    echo do_shortcode('[show-hide]'.$comments_output.'[/show-hide]');
    endif; ?>

    http://www.php.net/manual/en/function.ob-get-contents.php

    Thread Starter matreece

    (@matreece)

    Thanks for the code, however I’m getting an error saying:

    Fatal error: Function name must be a string in /homepages/11/d388105143/htdocs…

    Any ideas on how to fix this?

    Michael

    (@alchymyth)

    my mistake, an erraneous $ before comments_template();

    corrected:

    <?php if ( comments_open() || '0' != get_comments_number() ) :
    ob_start();
    comments_template();
    $comments_output = ob_get_contents();
    ob_end_clean();
    echo do_shortcode('[show-hide]'.$comments_output.'[/show-hide]');
    endif; ?>
    Thread Starter matreece

    (@matreece)

    Fantastic – works perfectly…Many thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Wrapping do_shortcode around additional php code’ is closed to new replies.