Skip to content

Instantly share code, notes, and snippets.

@joshuacharleslake
Last active November 16, 2020 05:08
Show Gist options
  • Save joshuacharleslake/8fc454c87706acb2829c to your computer and use it in GitHub Desktop.
Save joshuacharleslake/8fc454c87706acb2829c to your computer and use it in GitHub Desktop.
Add Shortcode for disqus embed.
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>';
}
<?php disqus_embed('THE SHORTNAME OF YOUR DISQUS'); ?>
@pixelloop
Copy link

If you adapt it to

add_shortcode('disqus-inserter', 'disqus_embed');
function disqus_embed() {
    global $post;
    wp_enqueue_script('disqus_embed','http://example.disqus.com/embed.js');
    return '<div id="disqus_thread"></div>
    <script type="text/javascript">
        var disqus_title = "'.$post->post_title.'";
        var disqus_url = "'.get_permalink($post->ID).'";
        var disqus_identifier = "example-'.$post->ID.'";
    </script>';
}

You can set the sitewide disqus account instead of "example" and insert anywhere into a post template using Divi, Beaver Builder or Types / WP Toolset using the shortcode [disqus-inserter]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment