0

I have a javascript that I am trying to add to a page from the WordPress dashboard. I select the page, choose text tab and add my description text and the javascript underneath it. But it will not work. However, I get no errors.

I have tested the page with this simple script and it works

<script type="text/javascript">
var a = 5;
alert("hello world. The value of a is: " + a);
</script>

However, when I punch my script in, it does not work.

If I take my script over to a test website and place my script in between the header tags in the HTML, it works just fine.

What may be some of the reasons why it won't work on my WordPress Page?

1 Answer 1

1

There are 3 ways you can excuse the script. One way which is easier way to do is following other 2 you will find here https://in.godaddy.com/blog/3-ways-insert-javascript-wordpress-pages-posts/ . As I took reference from this website only.

Step - 1 disabled the CUSTOM_TAGS from wp-config.php file

define( 'CUSTOM_TAGS', true );

Step - 2

In your theme's functions.php file add teh following code.

function add_scriptfilter( $string ) {
   global $allowedtags;
   $allowedtags['script'] = array( 'src' => array () );
   return $string;
}
 add_filter( 'pre_kses', 'add_scriptfilter' );

I hope this will work for you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.