• 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 = 'https://' + 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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter joshcanhelp

    (@joshcanhelp)

    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.

    Plugin Author dphiffer

    (@dphiffer)

    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');

    Thread Starter joshcanhelp

    (@joshcanhelp)

    Thanks for the reply… that’s a good addition.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Disqus plugin adding code to JSON API feed’ is closed to new replies.