Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Så här inaktiverar du Disqus på custom post types i WordPress

Behöver du inaktivera Disqus comments på custom post types i WordPress?

Ibland kan kommentarer försvinna från dina custom post types efter att du har bytt till Disqus. Detta händer när dina comments inte flyttas ordentligt, men tack och lov finns det en snabb och enkel fix.

I den här artikeln kommer vi att visa dig hur du inaktiverar Disqus comment system på custom post types i WordPress.

How to Disable Disqus on Custom Post Types in WordPress

Varför vi bytte bort Disqus

Tidigare har vi experimenterat med att använda Disqus comment system på WPBeginner. Vi bytte dock snabbt tillbaka till standard WordPress comments.

Det fanns flera anledningar till att vi bytte bort Disqus, men tidigt noterade vi att vissa kommentarer inte syntes på våra custom post types efter att ha gått över till Disqus.

Om du fortfarande använder Disqus för att hantera och granska kommentarer i WordPress är en lösning att importera dessa kommentarer manuellt. Detta kan dock ta mycket tid och ansträngning, viss om dina customize posts har många kommentarer.

Tack och lov finns det en snabbare lösning för Disqus användare. Med det i åtanke, låt oss se hur du snabbt och enkelt kan inaktivera Disqus för custom post types.

Inaktivera Disqus på custom post types i WordPress

Innan du kommer igång måste du se till att du har aktiverat synkronisering mellan Disqus och din website i WordPress.

I menyn till vänster väljer du Disqus och klickar sedan på tabben ”Syncing”. Du kan sedan klicka på ”Enable Auto Syncing” om den ej redan är aktiverad.

Make Sure You Have Enabled Syncing Between Disqus and WordPress

Note : Vid denna punkt kan du se följande error: ”Du måste ha ett Site Shortname, API Secret Key och API Access Tokens konfigurerat för att aktivera den här funktionen.” Om detta händer kommer vi att visa dig hur du fixar felet i slutet av posten.

Därefter måste du lägga till lite kod till din WordPress blogg.

Ofta kommer tutorials att be dig att editera ditt temas functions.php-filer direkt, men vi rekommenderar inte detta tillvägagångssätt, eftersom ett litet misstag kan orsaka ett antal vanliga WordPress error eller till och med förstöra din site helt.

Med detta sagt rekommenderar vi att du använder det gratis pluginet WPCode istället. Det är det enklaste och säkraste sättet att add to custom code i WordPress.

Efter aktivering, besök Code Snippets ” + Add Snippet page i din WordPress dashboard.

How to disable Disqus for custom post types using code

Here, you will see all the different ready-made snippets that you can add to your site. Dessa inkluderar snippets som tillåter dig att inaktivera widgetar block i WordPress och remove WordPress versionsnummer.

För att add to ditt eget snippet, hovera över ”Add Your Custom Code” och klicka sedan på ”Use snippet”.

Disabling Disqus using WPCode

På den här vyn skriver du in en titel för det anpassade code snippet. Det kan vara vad som helst som hjälper dig att identifiera PHP-snippet.

Därefter öppnar du bara dropdown för ”Code Type” och väljer ”PHP Snippet”.

How to add a PHP snippet to WordPress

Följ det genom att klistra in följande code snippet i Editorn:

function filter_dsq_can_load( $script_name ) {
if ( is_singular( 'custom_post_type_name' ) ) {
if ( 'count' === $script_name ) {
return false;
} elseif  ( 'embed' === $script_name ) {
return false;
} else {
return true;
}
}
}
add_filter( 'dsq_can_load', 'filter_dsq_can_load' );

Den här koden skapar ett filter som kontrollerar en specifik custom post type och sedan inaktiverar Disqus template för kommentarer.

Med detta i åtanke, se till att du ersätter custom_post_type_name med namnet på den custom post type där du vill inaktivera Disqus.

Under kodboxen ser du alternativen för infogning. Om det inte redan är valt, klicka på ”Auto Insert”-metoden så att snippet automatiskt infogas och körs över hela din WordPress blogg.

Därefter öppnar du dropdown ’Location’ och klickar på ’Run Everywhere’.

Running the Disqus code across your website

Sedan rullar du högst upp på vyn och klickar på ”Inaktiverad” toggle så att den ändras till ”Aktiv”.

Slutligen går du vidare och klickar på ”Save” för att göra Disqus snippet live.

How to publish the Disqus code snippet

Felsökning : Du måste ha ett Site Shortname, API Secret Key och API Access Tokens

När du försöker aktivera Disqus auto-synkronisering kan du få ett error: ”Du måste ha ett Site Shortname, API Secret Key och API Access Tokens konfigurerade för att aktivera den här funktionen.”

A Disqus error message

Om detta händer måste du skapa en Disqus-applikation genom att heada till Disqus website. Om du inte redan har gjort det kan du skapa ett gratis konto med din email address eller logga in med ett annat konto, t.ex. ditt Facebook- eller Twitter-konto.

När du har gjort det klickar du på länken ”Registering an application”.

Registering a Disqus app

På den här vyn kan du skriva in lite information om din ansökan, till exempel dess namn, din organisation och den website där du planerar att använda Disqus.

När du är nöjd med den information du har enter klickar du bara på ”Register my application”.

How to register a Disqus application

När du har gjort det rullar du till section ”Default Access”.

Du kan nu välja ”Läsa, skriva och hantera forum” i dropdown-menyn.

Changing the authentication status of a Disqus app

Efter det rullar du längst ner på vyn och clickar på ”Save Changes”.

You can now click on the ’Details’ tab.

The Disqus API settings

Efter det rullar du till sektionen ”OAuth Settings”.

Här hittar du API key, API secret och access token. Du måste add to denna information i inställningarna för Disqus plugin.

API settings, on the Disqus website

I WordPress dashboard väljer du Disqus i menyn till vänster.

Klicka sedan på tabben ”Site Configuration”.

The Disqus site configuration tab

På den här vyn måste du välja länken ”Click to make changes”.

Du kan nu add to API key, API secret och access token i de olika fälten. You will also need to add your site’s shortname om du inte redan har gjort det.

Updating the Disqus plugin settings

När du har gjort det klickar du på knappen ”Save”.

Om du nu väljer tabben ”Syncing” bör du se en new ”Enable Auto Syncing” knapp istället för ett error.

Enabling the auto sync feature in Disqus

Vi hoppas att denna tutorial hjälpte dig att lära dig hur du inaktiverar Disqus på custom post types i WordPress. You may also want to learn how to increase your blogg traffic and see our expert picks for the best social media plugins for WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Avslöjande: Vårt innehåll stöds av våra läsare. Det innebär att om du klickar på några av våra länkar, kan vi tjäna en provision. Se hur WPBeginner finansieras, varför det är viktigt, och hur du kan stödja oss. Här är vår editoriala process.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

Den ultimata WordPress-verktygslådan

Få GRATIS tillgång till vår verktygslåda - en samling WordPress-relaterade produkter och resurser som varje professionell användare bör ha!

Reader Interactions

14 kommentarerLämna ett svar

  1. Syed Balkhi

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Ludy Amano

    The new Disqus Plugin (2018) requires some changes on this code to work properly:

    function filter_dsq_can_load( $script_name ) {
    // $script_name is either ’count’ or ’embed’.
    if ( ’count’ === $script_name ) {
    return false;
    }

    return true;
    }
    add_filter( ’dsq_can_load’, ’filter_dsq_can_load’ );

    • Priyanka

      Do we need to add this code along with what mentioned in this blog?

  3. Arta

    Disqusting….

  4. Hemang Rindani

    WordPress is a great enterprise web content management service that allows a company to control website(s) effortlessly. With unlimited built-in tools and their flexibility & scalability, a developer can design website for any business requirements. It is advisable to keep the site interesting where adding a comment box will play a crucial role. Disqus is one of the easiest ways to add comment box on any page however sometimes it is essential to disable it on a few sections where you don’t require reader’s inputs. The method described in article is spot-on as I readily implemented it. Thanks for sharing.
    I feel Jetpack is a good alternative. It allows your readers to connect to your website and leave a comment in multiple ways. It uses default WordPress comment option, can connect to WordPress.com or allows users to login through Facebook, G+ and twitter. There are many other features that make Jetpack a great tool.

  5. Raunak Hajela

    You showed us how to disable disqus in custom post type but what about enable? I recently added disqus on my interview custom post type but it’s not working. Why? I created two custom post types i.e Interviews and Blog. It is working in blog post type but not in interviews post type. Tell me how should I fix it.

    This is my code of both custom post types. I am using genesis template here –

    //* Register Interviews Post Type (Changes by NSS)
    add_action( ’init’, ’create_interview_post_type’ );

    function create_interview_post_type() {

    $labels = array(
    ’name’ => __( ’Interviews’ ),
    ’singular_name’ => __( ’Interviews’ ),
    ’all_items’ => __(’All Interviews’),
    ’add_new’ => _x(’Add new’, ’Interviews’),
    ’add_new_item’ => __(’Add new’),
    ’edit_item’ => __(’Edit Interview’),
    ’new_item’ => __(’New Interview’),
    ’view_item’ => __(’View Interview’),
    ’search_items’ => __(’Search in Interviews’),
    ’not_found’ => __(’No Interviews found’),
    ’not_found_in_trash’ => __(’No Interviews found in trash’),
    ’parent_item_colon’ => ”
    );

    $args = array(
    ’labels’ => $labels,
    ’public’ => true,
    ’has_archive’ => true,
    ’rewrite’ => array(’slug’ => ’interviews’),
    ’taxonomies’ => array( ’category’, ’post_tag’ ),
    ’supports’ => array( ’title’, ’editor’, ’author’, ’thumbnail’ , ’custom-fields’, ’excerpt’, ’comments’)
    );

    register_post_type( ’interview’, $args);
    }

    //* Register Blog Post Type (Changes by NSS)
    add_action( ’init’, ’create_nssblog_post_type’ );

    function create_nssblog_post_type() {

    $labels = array(
    ’name’ => __( ’Blog’ ),
    ’singular_name’ => __( ’Blog’ ),
    ’all_items’ => __(’All Posts’),
    ’add_new’ => _x(’Add new’, ’Blog’),
    ’add_new_item’ => __(’Add new’),
    ’edit_item’ => __(’Edit Post’),
    ’new_item’ => __(’New Post’),
    ’view_item’ => __(’View Post’),
    ’search_items’ => __(’Search in Posts’),
    ’not_found’ => __(’No Posts found’),
    ’not_found_in_trash’ => __(’No Posts found in trash’),
    ’parent_item_colon’ => ”
    );

    $args = array(
    ’labels’ => $labels,
    ’public’ => true,
    ’has_archive’ => true,
    ’rewrite’ => array(’slug’ => ’blog’),
    ’taxonomies’ => array( ’category’, ’post_tag’ ),
    ’supports’ => array( ’title’, ’editor’, ’author’, ’thumbnail’ , ’custom-fields’, ’excerpt’, ’comments’ )
    );

    register_post_type( ’nssblog’, $args);
    }

  6. Wakil Nikzad

    Thank you for this great post.
    We’ve installed and configured Disqus plugin in our website. everything is almost great with it, except default commenting option. I wonder if there is any option for choosing Guest Commenting as default.
    However there are a lots of people who have Disqus account, but it differs in different societies/countries. For example: in Afghanistan most of the internet users don’t know about Disqus.

    • Travis Pflanz

      You don’t need a Disqus account to comment on the Disqus system. You have to option to use Facebook, Twitter, Google+, Name/Email or Guest.

      I’m always logged in, so I had to logout to make sure this is the case.

      Logout and take a look.

  7. danh

    I see what you are doing and like it. I think I’m having a load order problem. If I doctor the disqus plugin code to not add filter when my custom post type is being used, it addresses my problem:

    if ( ’custom_post_type_name’ != get_post_type() ){
    add_filter(’comments_template’, ’dsq_comments_template’);
    }

    If I try your suggestion of removing the filter if it has been added, then it doesn’t work for me. I presume that functions.php is being executed before disqus.php, so there is no filter to remove at the time the removal is executed. I still haven’t worked out a fix.

  8. Piku

    Great article

  9. Erik

    Thanks for sharing.

  10. Akash Agarwal

    yes it is. I just in search of it. Its help me a lot. Thanks for sharing such useful and informative post.

  11. Manuel Edburg

    Woah. Interesting article! I noticed that and thought it was some error. I never knew this was possible.

  12. Eduardinho Teixeira

    Ok, i see… In case i disable Disqus in custom post type, what happens then? Does that post stay with comments disabled? Or in that case, WP Comments are back to the page?

Lämna ett svar

Tack för att du väljer att lämna en kommentar. Tänk på att alla kommentarer modereras enligt våra policy för kommentarer, och din e-postadress kommer INTE att publiceras. Vänligen använd INTE nyckelord i namnfältet. Låt oss ha en personlig och meningsfull konversation.