简体   繁体   中英

<script> tags aren't working in Wordpress

All, I have some script tags that are not working in Wordpress. If I have the following code:

<script type="text/javascript">
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '<?= 1234?>',
      status     : true, 
      cookie     : true,
      xfbml      : true,
      oauth      : true,
    });

    FB.Event.subscribe('auth.login', function(response) {
      window.location.reload();
    });
  };

  (function(d){
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     d.getElementsByTagName('head')[0].appendChild(js);
   }(document));
</script>

When I preview this in my browser it looks like this:

<script type="text/javascript">
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '123',
      status     : true, 
      cookie     : true,
      xfbml      : true,
      oauth      : true,
    });</p>
<p>        FB.Event.subscribe('auth.login', function(response) {
      window.location.reload();
    });
  };</p>
<p>      (function(d){
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     d.getElementsByTagName('head')[0].appendChild(js);
   }(document));
</script>

Which I believe is causing the program not to execute what is in the script tags. How can I prevent this from happening?

您需要将该脚本放在模板中,而不是在内容编辑器中。

Wordpress converts script tags in the editor to their HTML entity even in HTML mode. Therefore you can't add JavaScript this way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM