1

I want to include some jquery plugin files to my wordpress multisite install. My solution involved creating a specific template file for the pages that required these jquery plugins. Below is the line of code that includes my javascript file which I have placed at the last line of the template file.

<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/plugins/jquery.tablesorter.min.js" ></script>

Is this solution a safe way to include files in specific templates? Any feedback would be very helpful!

  • 1
    There's nothing dangerous about adding a JS script as long as it doesn't include any sensitive information. JS is fully exposed to client, you shouldn't do it anyway. Just make sure that src resolves and you don't expose any back-end code to front-end. – N00b Nov 16 '16 at 1:31
4

As @N00b mentioned Yes, it is safe adding a JS script as long as it doesn't include any sensitive information. JS is fully exposed to client, you shouldn't do it anyway.

But your situtaion it is better to create a site specific custom plugin and add JS using it.

Example :

function themeslug_enqueue_style() {
    wp_enqueue_style( 'core', 'style.css', false ); 
}

function themeslug_enqueue_script() {
    wp_enqueue_script( 'my-js', 'filename.js', false );
}

add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_style' );
add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_script' );

More Details : Plugin API/Action Reference/wp enqueue scripts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.