In this will guide, we're going to show you how to create a short code for the wpDiscuz, allowing you to custom position comments anywhere on your single post or custom post type. The wpDiscuz is a great tool for comment management on high traffic WordPress websites, and it's the one that we use on this blog. If you want to add it to a custom location on your WordPress website, creating a short code for wpDiscuz, and then placing that shortcode anywhere on the page is a great way to do that.
To create a shortcode for wpDiscuz, it's no different than creating a short code for the standard WordPress comments feature. The reason behind this is due to the fact that the wpDiscuz simply replaces the standard WordPress comments PHP with its own. Therefore, anywhere a normal WordPress comments section shows up on the site, the wpDiscuz will replace it with its own design and functionality.
So, to create a short code for wpDiscuz, all you need to do is paste in the following code, which is a direct copy of the code used to create a custom WordPress comments shortcode.
This code (source) should be added to your functions.PHP on your child theme, or by a code manager like Advanced Scripts (recommended method). It should be loaded in on “plugins loaded”.
/**
* Display the comment template with the [wpse_comments_template]
* shortcode on singular pages.
*
* @see http://stackoverflow.com/a/28644134/2078474
*/
add_shortcode( 'wpse_comments_template', function( $atts = array(), $content = '' )
{
if( is_singular() && post_type_supports( get_post_type(), 'comments' ) )
{
ob_start();
comments_template();
add_filter( 'comments_open', 'wpse_comments_open' );
add_filter( 'get_comments_number', 'wpse_comments_number' );
return ob_get_clean();
}
return '';
}, 10, 2 );
function wpse_comments_open( $open )
{
remove_filter( current_filter(), __FUNCTION__ );
return false;
}
function wpse_comments_number( $open )
{
remove_filter( current_filter(), __FUNCTION__ );
return 0;
}
Code language: PHP (php)
Now, if you want to place your wpDiscuz comments section anywhere on your website, simply paste in the following short code, navigate to the front end, and see the comments section in the new position.
[wpse_comments_template]
Code language: JSON / JSON with Comments (json)
TESTED WORKING JAN 2021 (Oxygen Builder, Elementor)
I tried this in Oxygen Builder and the comments do show up wherever the shortcode is placed. However, wpDiscuz still does not load on the backend or frontend. What do you mean when you say Working with Oxygen Builder? Is there another tutorial that gets wpDiscuz working with Oxygen?
Hello can i ask you a question. I used your code and workds fine but the bubble dissapeared.