WordPress.org

Ready to get started?Download WordPress

Forums

JSON API
Disqus plugin adding code to JSON API feed (4 posts)

  1. joshcanhelp
    Member
    Posted 3 years ago #

    The JSON API plugin is working great but I ran into a problem when trying to combine with the Disqus plugin. When the plugin is activated, a block of HTML is added to the JSON feed and causing it to break the elements using this feed. Here's what's added:

    <script type="text/javascript">
    	// <![CDATA[
    		var disqus_shortname = 'something';
    		var disqus_domain = 'disqus.com';
    		(function () {
    			var nodes = document.getElementsByTagName('span');
    			for (var i = 0, url; i < nodes.length; i++) {
    				if (nodes[i].className.indexOf('dsq-postid') != -1) {
    					nodes[i].parentNode.setAttribute('data-disqus-identifier', nodes[i].getAttribute('rel'));
    					url = nodes[i].parentNode.href.split('#', 1);
    					if (url.length == 1) url = url[0];
    					else url = url[1]
    					nodes[i].parentNode.href = url + '#disqus_thread';
    				}
    			}
    			var s = document.createElement('script'); s.async = true;
    			s.type = 'text/javascript';
    			s.src = 'http://' + disqus_domain + '/forums/' + disqus_shortname + '/count.js';
    			(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
    		}());
    	//]]>
    	</script>

    I'm already hacking the plugin a bit to remove body text so I don't mind making changes to the code, just not sure where to start.

    Also checking with Disqus but I figured modifying this plugin would be easier (with less downstream effects, likely).

    Thanks!

  2. joshcanhelp
    Member
    Posted 3 years ago #

    For anyone having this issue...

    I contacted Disqus support and there is an option for Disqus called "Output Javascript in footer." Go to Comments > Disqus and look on the top right for Advanced Options. Click that and check the box for this option. You'll need to have wp_footer() in footer.php but this stops putting it in the header.

  3. dphiffer
    Member
    Plugin Author

    Posted 3 years ago #

    Thanks for the heads up Josh. I found another workaround that will make its way into the next release. Adding this into JSON_API_Response::setup prevents Disqus from getting up in my business:
    remove_action('loop_end', 'dsq_loop_end');

  4. joshcanhelp
    Member
    Posted 3 years ago #

    Thanks for the reply... that's a good addition.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic