admin管理员组

文章数量:1026620

I'm trying to add some JavaScript into one of my Wordpress pages. When I change the text area to HTML mode and paste in the JavaScript then save my changes. It does not appear on the page itself. Can someone please help me allow JavaScript in the default Wordpress page text editor?

The JavaScript that I am trying to input is:

<script type="text/javascript">
    jQuery(function($){
        $.supersized({
            random : 1,
            slide_interval : 3000,
            transition : 3,
            transition_speed : 900,
            slide_links : 'blank',
        });
    });
</script>

I'm trying to add some JavaScript into one of my Wordpress pages. When I change the text area to HTML mode and paste in the JavaScript then save my changes. It does not appear on the page itself. Can someone please help me allow JavaScript in the default Wordpress page text editor?

The JavaScript that I am trying to input is:

<script type="text/javascript">
    jQuery(function($){
        $.supersized({
            random : 1,
            slide_interval : 3000,
            transition : 3,
            transition_speed : 900,
            slide_links : 'blank',
        });
    });
</script>
Share Improve this question edited Aug 6, 2018 at 18:07 YakovL 8,40513 gold badges73 silver badges113 bronze badges asked Sep 10, 2011 at 9:56 cvandalcvandal 7946 gold badges19 silver badges32 bronze badges 1
  • Take a look at this document: codex.wordpress/Using_Javascript#Javascript_in_Posts – GianluKa Commented Sep 10, 2011 at 9:59
Add a ment  | 

2 Answers 2

Reset to default 2

WordPress is really picky about how you do the newlines and it will sometimes place <p> tags in there which will mess up JavaScript code. I would remend looking at the source after you make the post and see if any of the <p> tags got incorporated. If so, go back and delete the white-spacing in that area and try again.

In the worst case, you can always use the Raw HTML plugin which will render the raw code for you:

http://wordpress/extend/plugins/raw-html/

You, or others viewing this question, might also want to try my plugin which enables support for inline JavaScript and JavaScript code blocks in the HTML editor tab. You don't have to use a shortcode or special markup and you can continue to use the TinyMCE wysiwyg editor without worrying too much about losing the content... If you delete everything in the Visual editor, you'll lose the code block, but edits, additions and targeted deletions of content are fully patible.

It also preserves whitespace and indentation of HTML code when you switch between the HTML and Visual tabs among a few other minor features.

http://wordpress/extend/plugins/preserved-html-editor-markup/

I'm trying to add some JavaScript into one of my Wordpress pages. When I change the text area to HTML mode and paste in the JavaScript then save my changes. It does not appear on the page itself. Can someone please help me allow JavaScript in the default Wordpress page text editor?

The JavaScript that I am trying to input is:

<script type="text/javascript">
    jQuery(function($){
        $.supersized({
            random : 1,
            slide_interval : 3000,
            transition : 3,
            transition_speed : 900,
            slide_links : 'blank',
        });
    });
</script>

I'm trying to add some JavaScript into one of my Wordpress pages. When I change the text area to HTML mode and paste in the JavaScript then save my changes. It does not appear on the page itself. Can someone please help me allow JavaScript in the default Wordpress page text editor?

The JavaScript that I am trying to input is:

<script type="text/javascript">
    jQuery(function($){
        $.supersized({
            random : 1,
            slide_interval : 3000,
            transition : 3,
            transition_speed : 900,
            slide_links : 'blank',
        });
    });
</script>
Share Improve this question edited Aug 6, 2018 at 18:07 YakovL 8,40513 gold badges73 silver badges113 bronze badges asked Sep 10, 2011 at 9:56 cvandalcvandal 7946 gold badges19 silver badges32 bronze badges 1
  • Take a look at this document: codex.wordpress/Using_Javascript#Javascript_in_Posts – GianluKa Commented Sep 10, 2011 at 9:59
Add a ment  | 

2 Answers 2

Reset to default 2

WordPress is really picky about how you do the newlines and it will sometimes place <p> tags in there which will mess up JavaScript code. I would remend looking at the source after you make the post and see if any of the <p> tags got incorporated. If so, go back and delete the white-spacing in that area and try again.

In the worst case, you can always use the Raw HTML plugin which will render the raw code for you:

http://wordpress/extend/plugins/raw-html/

You, or others viewing this question, might also want to try my plugin which enables support for inline JavaScript and JavaScript code blocks in the HTML editor tab. You don't have to use a shortcode or special markup and you can continue to use the TinyMCE wysiwyg editor without worrying too much about losing the content... If you delete everything in the Visual editor, you'll lose the code block, but edits, additions and targeted deletions of content are fully patible.

It also preserves whitespace and indentation of HTML code when you switch between the HTML and Visual tabs among a few other minor features.

http://wordpress/extend/plugins/preserved-html-editor-markup/

本文标签: phpWordpress insert javascript into page text areaStack Overflow