• Resolved aslamK

    (@4slam)


    I got the code for the Follow button from the generator. Upon adding it as a Custom HTML widget, it resulted in the following code:

    <aside id="block-45" class="widget widget_block"><a class="wordpress-follow-button"  data-blog="https://melange.dmaculate.me/home" data-lang="en">Follow dMaculate.melange on WordPress.com</a>
    (function(d){var f = d.getElementsByTagName('SCRIPT')[0], p = d.createElement('SCRIPT');p.type = 'text/javascript';p.async = true;p.src = '//widgets.wp.com/platform.js';f.parentNode.insertBefore(p,f);}(document));</aside>

    This is what appears on the page:

    Follow dMaculate.melange on WordPress.com (function(d){var f = d.getElementsByTagName(‘SCRIPT’)[0], p = d.createElement(‘SCRIPT’);p.type = ‘text/javascript’;p.async = true;p.src = ‘//widgets.wp.com/platform.js’;f.parentNode.insertBefore(p,f);}(document));

    Why is the JavaScript from the <script /> tag rendering on the page? How can I fix it so that it renders the Follow button?

    • This topic was modified 1 year, 3 months ago by aslamK.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Sara

    (@sarayourfriend)

    Issues with the WordPress.com follow button generator should be taken up with WordPress.com’s support: https://wordpress.com/support/

    There is a link at the bottom to get in touch with WordPress.com’s support folks.

    For what it’s worth, if you’re pasting the HTML into a WordPress post and haven’t granted permissions to enable unfiltered HTML from your user, then WordPress is going to strip the script tags. The snippet you’ve shared is missing the script tags that the generator includes. The script tag is necessary to tell browsers to view the JavaScript code as code to execute rather than just regular text. You can read more about the unfiltered_html user capability in the documentation for it, but be aware that there are potential and significant security issues if it isn’t applied carefully. Enabling that would stop the site from stripping the script tag.

    Thread Starter aslamK

    (@4slam)

    @sarayourfriend thank you for the explanation. Very helpful.

    I posted the question here, instead of wordpress.com support, because I thought it was an HTML/JS issue, not specific to the Follow button. Turns out it’s both. According to the link you shared, “In WordPress Multisite, only Super Admins have the unfiltered_html capability.” I added the widget as a site Administrator, not as Super Admin, which would explain why the script tags are getting stripped.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Javascript appears on page’ is closed to new replies.