WordPress.org

Ready to get started?Download WordPress

Forums

Enqueue-ing scriptaculous breaks visual editor (1 post)

  1. alexleonard
    Member
    Posted 6 years ago #

    Hi there,

    I've been looking around at various ways of correctly loading scripts for a project I'm helping a friend with.

    One of the areas of the website requires a scriptaculous effect, which I have gotten working correctly by updating the pre-loaded version of prototype, and then changing my header.php file to read as:

    <?php wp_head(); ?>
    <script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/js/scriptaculous-1.8.1/scriptaculous.js"></script>
    <script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/js/scriptaculous-1.8.1/accordion.js"></script>
    </head>

    This works fine and everything in both the front end and the admin areas works.

    I thought that I would try to improve this by what I believed to be the more correct way of adding those scripts through add_action in functions.php.

    I added the following function to functions.php:

    function myplugin_init() {
    	if (function_exists('wp_enqueue_script')) {
    
    		// for new libraries
    		wp_register_script('scriptaculous', get_bloginfo('wpurl') . '/wp-content/themes/new/js/scriptaculous-1.8.1/scriptaculous.js', array('prototype'), '1.8.1');
    		wp_enqueue_script('scriptaculous');
    		// for new libraries
    		wp_register_script('accordion', get_bloginfo('wpurl') . '/wp-content/themes/new/js/scriptaculous-1.8.1/accordion.js', array('prototype'));
    		wp_enqueue_script('accordion');
    	}
    }
    add_action('init', 'myplugin_init');

    This continued to work as expected on the front end, however in the admin section it appears to have broken the visual editor - is there some conflict with tinymce going on?

Topic Closed

This topic has been closed to new replies.

About this Topic