Skip to content

Instantly share code, notes, and snippets.

@jamesmrobinson
Last active January 26, 2016 11:28
Show Gist options
  • Save jamesmrobinson/162e87b694a9418c1380 to your computer and use it in GitHub Desktop.
Save jamesmrobinson/162e87b694a9418c1380 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: WP Disqus Embed
* Plugin URI: https://imaginarymedia.com.au/2015/02/11/wordpress-plugin-to-embed-disqus/
* Description: A plugin to add Disqus embedding support via shortcode
* Version: 0.1
* Author: Imaginary Media
* Author URI: https://imaginarymedia.com.au/
* License: GPL2
*/
/* Copyright 2015 Imaginary Media (email : support@imaginarymedia.com.au)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if ( !defined( 'ABSPATH' ) ) exit;
// Create Disqus Shortcode
function disqus_embed($atts, $content = null) {
extract(shortcode_atts(array("shortname" => ''), $atts));
if ( $shortname != '') {
$html = '<div id="disqus_thread"></div>
<script>
(function() {
var dsq = document.createElement("script");
dsq.async = true;
dsq.src = "//' . $shortname . '.disqus.com/embed.js";
(document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(dsq);
})();
</script>';
return $html;
}
}
add_shortcode('disqus-comments', 'disqus_embed');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment