Archived topic
Add jQuery code, js scripts, css links etc.
17 replies · Started by Leonardo on January 7, 2019
It's not so much the theme, it's that WordPress itself doesn't allow <script> tags in the content editor. They do this for security reasons.
One option is to build a shortcode, which you can then place in your content.
For example:
add_shortcode( 'my_ad', function() {
?>
<script>YOUR SCRIPT IN HERE</script>
<?php
} );
Then you can add this to your content area: [my_ad]
Sorry, Tom, I appreciate your prompt responses, but
your code has a problem.
I tried it directly in the page content. Certainly replaced the "Your script in here" with my script.
Saved opened the page and ... got this text on the screen:
add_shortcode( ‘my_ad’, function() {
?>
Please correct and update. I agree that this is common to WordPress so there must be plenty of good solutions. You said the suggested code is just one possibility could you be so kind and offer some other options. I am puzzled that we dropped the wp-footer hook topic. I was under the impression from your tutorial video that this is the preferred approach. What am I missing?
That code should be added using one of these methods: https://docs.generatepress.com/article/adding-php/
Then you can use the shortcode in your content: [my_ad]