Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Strange issue with WP Shortcode

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #43903
    bastunqk
    Participant

    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.

    #130725
    bastunqk
    Participant

    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)
  • The forum ‘Back End’ is closed to new topics and replies.