Integrating Disqus Into WordPress Without a Plugin
As we discussed earlier, doing stuff without plugins helps us optimize our website - a single query is a single query, right?
Anyways, here are the functions that we're going to use - like always, add these inside your theme's functions.php file:
Embedding Disqus Comments
function disqus_embed($disqus_shortname) {
global $post;
wp_enqueue_script('disqus_embed','http://'.$disqus_shortname.'.disqus.com/embed.js');
echo '<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = "'.$disqus_shortname.'";
var disqus_title = "'.$post->post_title.'";
var disqus_url = "'.get_permalink($post->ID).'";
var disqus_identifier = "'.$disqus_shortname.'-'.$post->ID.'";
</script>';
}
The function is pretty simple: Use the code <?php disqus_embed('myexampleblog'); ?>
anywhere you want in your single.php and page.php files to embed and show Disqus comments for that page. You can search for the comments_template(); function and replace it with our new function, since we're not going to use the native commenting functions anymore.