Grow your CSS skills. Land your dream job.

Strange issue with WP Shortcode

  • # April 5, 2013 at 5:56 am

    Hi.
    I have strange issue with WP Shortcode. I want to make shortcode which will put comments where i want it. Here is the shortcode:


    function custom_comment_func( $atts ){
    $comments = comments_template();
    return 'div class="comment-wrapper"' . $comments . '/div';
    }

    add_shortcode( 'custom_comment', 'custom_comment_func' );

    And shortcode work’s but the problem is that instead to put comments on bottom where i put the shortcode it is always put’s it on top before content. Maybe some issue with execution ? I dont know. Please give some idea where i got wrong. Thanks.

    # April 5, 2013 at 7:34 am

    I’ve done it using buffer.
    Here is my solution:


    function bnt_custom_comment_func( $atts ){

    ob_start();
    comments_template();
    $output_string = ob_get_contents();
    ob_end_clean();
    return '
    ' .$output_string . '
    ';
    }

    add_shortcode( 'bnt_custom_comment', 'bnt_custom_comment_func' );

    If there is other solution’s please tell.
    Regards.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".