A volte i commenti possono scomparire dai post type / tipi di contenuto personalizzati dopo il passaggio a Disqus.
Abbiamo usato Disqus in passato, quindi conosciamo bene le sue stranezze, e abbiamo scoperto che questo può accadere se i commenti non vengono migrati correttamente.
Per fortuna esiste una correzione semplice e veloce.
In questo articolo vi mostreremo come disabilitare il sistema di commenti Disqus sui post type / tipo di contenuto personalizzati in WordPress. Seguendo alcuni semplici passaggi, potrete correggere questo problema e riportare i commenti al loro posto.

Perché ci siamo allontanati da Disqus
In passato abbiamo sperimentato l’uso del sistema di commenti Disqus su WPBeginner. Tuttavia, siamo tornati rapidamente ai commenti predefiniti di WordPress.
I motivi che ci hanno spinto ad abbandonare Disqus sono diversi, ma all’inizio abbiamo notato che alcuni commenti non comparivano sui nostri tipi di post personalizzati dopo il passaggio a Disqus.
Se si utilizza ancora Disqus per gestire e moderare i commenti in WordPress, una soluzione è importare manualmente i commenti. Tuttavia, questa operazione può richiedere molto tempo e fatica, soprattutto se i vostri post personalizzati hanno molti commenti.
Fortunatamente, esiste una soluzione più rapida per gli utenti di Disqus. Con questa premessa, vediamo come disattivare Disqus per i tipi di post personalizzati in modo semplice e veloce.
Disabilitare Disqus sui tipi di post personalizzati in WordPress
Prima di iniziare, è necessario assicurarsi di aver abilitato la sincronizzazione tra Disqus e il proprio sito web WordPress.
Nel menu di sinistra, selezionare Disqus e poi fare clic sulla scheda “Sincronizzazione”. È possibile fare clic su “Abilita la sincronizzazione automatica”, se non è già attiva.

Nota: a questo punto, potrebbe essere visualizzato il seguente errore: “Per abilitare questa caratteristica è necessario che siano configurati un Site Shortname, una API Secret Key e un API Access Token”.
Se ciò dovesse accadere, alla fine della pubblicazione vi mostreremo come correggere l’errore.
Successivamente, è necessario aggiungere del codice al proprio sito WordPress.
Spesso i tutorial vi chiederanno di modificare direttamente i file functions.php del vostro tema, ma non vi consigliamo questo approccio, perché un piccolo errore potrebbe causare una serie di errori comuni di WordPress o addirittura rompere completamente il vostro sito.
Detto questo, consigliamo di utilizzare il plugin gratuito WPCode. È il modo più semplice e sicuro per aggiungere codice personalizzato in WordPress.
Abbiamo testato a fondo lo strumento e lo abbiamo trovato super affidabile. Per saperne di più, consultate la nostra recensione di WPCode.
Nota: è possibile passare al piano pro di WPCode per sbloccare la libreria cloud di frammenti di codice, la creazione di blocchi personalizzati, la logica condizionale intelligente e altro ancora.
Dopo l’attivazione, visitare la pagina Code Snippets “ + Add Snippet nella dashboard di WordPress.

Qui vengono mostrati tutti i diversi snippet già pronti che è possibile aggiungere al proprio sito. Questi includono snippet che consentono di disabilitare i blocchi di widget in WordPress e di rimuovere il numero di versione di WordPress.
Per aggiungere il proprio snippet, passare il mouse su “Aggiungi il tuo codice personalizzato” e fare clic su “Usa snippet”.

In questa schermata, digitare un titolo per lo snippet di codice personalizzato. Può essere qualsiasi cosa che aiuti a identificare lo snippet PHP.
Quindi, aprire il menu a tendina “Tipo di codice” e selezionare “Snippet PHP”.

A questo punto, è sufficiente incollare il seguente frammento di codice nell’editor:
1 2 3 4 5 6 7 8 9 10 11 12 | 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' ); |
Questo codice crea un filtro che controlla uno specifico tipo di post personalizzato e poi disabilita il modello di commento Disqus.
Per questo motivo, assicurarsi di sostituire custom_post_type_name
con il nome del tipo di post personalizzato in cui si desidera disabilitare Disqus.
Sotto il riquadro del codice, vengono visualizzate le opzioni di inserimento. Se non è già selezionata, fate clic sul metodo “Inserisci automaticamente”, in modo che lo snippet venga inserito ed eseguito automaticamente in tutto il vostro blog WordPress.
Quindi, aprire il menu a tendina “Posizione” e fare clic su “Esegui ovunque”.

Quindi, scorrere fino alla parte superiore dello schermo e fare clic sulla levetta “Inattivo” in modo che diventi “Attivo”.
Infine, fare clic su “Salva” per rendere attivo lo snippet Disqus.

Risoluzione dei problemi: È necessario disporre di un nome breve del sito, una chiave segreta API e un token di accesso API
Quando si tenta di attivare la sincronizzazione automatica di Disqus, è possibile che venga visualizzato un errore: “Per abilitare questa funzione è necessario avere un nome breve del sito, una chiave segreta API e un token di accesso API configurati”.

In questo caso, è necessario creare un’applicazione Disqus collegandosi al sito web di Disqus. Se non l’avete ancora fatto, potete creare un account gratuito utilizzando il vostro indirizzo e-mail o accedere con un altro account, come quello di Facebook o Twitter.
A questo punto, cliccate sul link “Registrazione di una domanda”.

In questa schermata è possibile digitare alcune informazioni sulla propria applicazione, come il nome, l’organizzazione e il sito web in cui si intende utilizzare Disqus.
Una volta soddisfatti delle informazioni inserite, basta cliccare su “Registra la mia domanda”.

A questo punto, scorrete fino alla sezione “Accesso predefinito”.
Ora è possibile scegliere “Leggere, scrivere e gestire i forum” dal menu a discesa.

Quindi, scorrere fino alla parte inferiore della schermata e fare clic su “Salva modifiche”.
A questo punto è possibile fare clic sulla scheda “Dettagli”.

Successivamente, scorrere fino alla sezione “Impostazioni OAuth”.
Qui si trovano la chiave API, il segreto API e il token di accesso. È necessario aggiungere queste informazioni alle impostazioni del plugin Disqus.

Nella dashboard di WordPress, selezionate Disqus dal menu di sinistra.
Quindi, fare clic sulla scheda “Configurazione del sito”.

In questa schermata, è necessario selezionare il link “Fare clic per apportare modifiche”.
Ora è possibile aggiungere la chiave API, il segreto API e il token di accesso nei diversi campi. È necessario aggiungere anche il nome breve del sito, se non è già stato fatto.

A questo punto, fare clic sul pulsante “Salva”.
Ora, se si seleziona la scheda “Sincronizzazione”, si dovrebbe vedere un nuovo pulsante “Attiva sincronizzazione automatica” invece di un errore.

Speriamo che questo tutorial vi abbia aiutato a capire come disabilitare Disqus sui post type / tipo di contenuto personalizzati in WordPress. Potreste anche voler imparare a eliminare di massa tutti i commenti di WordPress e consultare la nostra guida per principianti sulla moderazione dei commenti di WordPress.
Se questo articolo vi è piaciuto, iscrivetevi al nostro canale YouTube per le esercitazioni video su WordPress. Potete trovarci anche su Twitter e Facebook.
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?
Arta
Disqusting….
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.
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);
}
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.
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.
Piku
Great article
Erik
Thanks for sharing.
Akash Agarwal
yes it is. I just in search of it. Its help me a lot. Thanks for sharing such useful and informative post.
Manuel Edburg
Woah. Interesting article! I noticed that and thought it was some error. I never knew this was possible.
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?