如何在wp_footer动作中传递变量?

我正在创建Elementor页面构建器小部件。我不希望添加嵌入式Java脚本。我正在使用” wp_footer”动作。我想在add_action / wp_footer / function(){$$$这里$$$$}中传递变量。

没有Java脚本错误。

$var_1 = '100';
$var_2 = '200';

add_action( 'wp_footer', function() { 
<script>
   (function($) {
      'use strict';
          $('.id').numerator({
                easing: 'linear', duration: '<?= $var_1; ?>', toValue:'<?= $var_2; ?>', });
    })(jQuery);
</script>
}

#1


那些变量不应该在函数内部吗?使用全局变量呢?


#2


这不是一个好习惯, 但是如果你要这样做, 则下面的代码。关键是将所有内容作为字符串处理。如果使用引号, 则可以轻松地对变量进行分类。

$var_1 = '100';
$var_2 = '200';

add_action( 'wp_footer', function() { 

echo "<script>
 (function($) {
  'use strict';
     $('.id').numerator({
            easing: 'linear', duration: '$var_1', toValue: '$var_2', });
  })(jQuery);
</script>";
}

来源:

https://www.srcmini02.com/63422.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37626.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?