I am trying to use a javascript file from an external source on my WordPress site and can't seem to get it to work. It is a specific Captcha I need to include.
The directions from the site are to include the following:
In the HTML include the following:
<div data-captcha-enable="true"></div>
Add the following JavaScript in the body (site info hidden in asteriks) :
<script src="//*site*/captcha.js.php?id=*xxx*"></script>
Including both of those in the HTML of a page did not work, and reading into WordPress allowance of scripts it seems this is intentional.
So next I tried to include it in the functions.php through
function wpTest_scripts() {
wp_register_script('captcha', '//*site*/captcha.js.php?id=*xxx*', false);
wp_enqueue_script( 'captcha' );
}
add_action('wp_enqueue_scripts', 'wpTest_scripts');
I tried a ton of different varieties of this, and including all sorts variations of
<script src="//*site*/captcha.js.php?id=*xxx*"></script>
in the header, main body etc.
Finally as a last stab I tried to follow advice for allowing scripts in pages within a WordPress site globally. I know this isn't as secure, but there are no other users of the page and it is a very simple page. This is also creating an error:
In wp-config.php
define( 'CUSTOM_TAGS', true );
In functions.php
function add_scriptfilter( $string ) {
global $allowedtags;
$allowedtags['script'] = array( 'src' => array () );
return $string;
}
add_filter( 'pre_kses', 'add_scriptfilter' );
This creates an error from the functions.php in this line:
$allowedtags['script'] = array( 'src' => array () );
The error is: Parse error: syntax error, unexpected '=', expecting ')' in
The easiest way might be just by opening the footer.php
file of your current active theme.
And pasting the code just before </body>
<?php wp_footer(); // and other stuff above ?>
<script src="//*site*/captcha.js.php?id=*xxx*"></script>
</body>
</html>
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.