How To Add WPDisquz To Custom Locations With A Shortcode

Published: 1 week ago

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;
}

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] 

TESTED WORKING JAN 2021 (Oxygen Builder, Elementor)

Join Our Newsletter
Here's what you get: A once a week newsletter that contains original content, aggregated posts, WordPress deals, and anything else we think you'd like. We don't spam or sell your email address. Unsub at any time.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Affiliate Disclosure: Some links on this website are affiliate links. We make commissions for purchases made through those links.

We only recommend items/tools that we've personally used and like.

Full Disclosure | FTC Statement

Join Our Newsletter
Over 4,000 Design Lovers and Problem Solvers.
rocket.net

Author

  • James LePage is the founder of Isotropic Design, a digital agency that builds WordPress websites. I read, write and design constantly!

A relationship driven website creation company.

Connect

© ISOTROPIC, LLC 2016-2021
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram