如何在wordpress中使用外部javascript/php
我试图在我的WordPress站点上使用来自外部源的javascript文件,但似乎无法使其正常工作。这是我需要包含的特定验证码 现场指示应包括以下内容:如何在wordpress中使用外部javascript/php,javascript,php,wordpress,Javascript,Php,Wordpress,我试图在我的WordPress站点上使用来自外部源的javascript文件,但似乎无法使其正常工作。这是我需要包含的特定验证码 现场指示应包括以下内容: <div data-captcha-enable="true"></div> 在HTML中,包括以下内容: <div data-captcha-enable="true"></div> 我尝试了很多不同的品种,包括各种各样的 <script src="//*site*/captcha.
<div data-captcha-enable="true"></div>
在HTML中,包括以下内容:
<div data-captcha-enable="true"></div>
我尝试了很多不同的品种,包括各种各样的
<script src="//*site*/captcha.js.php?id=*xxx*"></script>
在functions.php中
function add_scriptfilter( $string ) {
global $allowedtags;
$allowedtags['script'] = array( 'src' => array () );
return $string;
}
add_filter( 'pre_kses', 'add_scriptfilter' );
这会在这一行的functions.php中创建一个错误:
$allowedtags['script'] = array( 'src' => array () );
错误是:Parse error:syntax error,意外的“=”,预期的“'),在中最简单的方法可能是打开当前活动主题的
footer.php
文件
并在
谢谢您的建议,但不幸的是,这不起作用。=
应该是=>
。。。您正在编写代码,而不是html实体。感谢您修复了错误。不幸的是,它仍然没有运行javascript。我收回这一点——我现在可以很好地运行代码了。事实证明,验证码的JS文件就是问题所在。
function add_scriptfilter( $string ) {
global $allowedtags;
$allowedtags['script'] = array( 'src' => array () );
return $string;
}
add_filter( 'pre_kses', 'add_scriptfilter' );
$allowedtags['script'] = array( 'src' => array () );
<?php wp_footer(); // and other stuff above ?>
<script src="//*site*/captcha.js.php?id=*xxx*"></script>
</body>
</html>