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
  • 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. Commented Nov 16, 2016 at 1:31

1 Answer 1

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

0

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.