Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have written a function to register a script in the admin interface.

function custom_admin_js() {
    $url = get_bloginfo('template_directory') . '/admin/admin.js';
    echo '<script type="text/javascript" src="'. $url . '"></script>';
}
add_action('admin_footer', 'custom_admin_js');

For some - for me unknown reason - this creates additional quotes surrounding the script.

"<script type="text/javascript" src="http://test121.uphero.com/wp-content/themes/news/admin/admin.js"></script>"

How do I remove the surrounding quotes?

share|improve this question
add comment

1 Answer

I am not sure about the extra quotes. The best way to include a java script file is with wp_enqueue_script() as indicated here in the codex.

The safe and recommended method of adding JavaScript to a WordPress generated page and WordPress Theme or Plugin is by using wp_enqueue_script(). This function includes the script if it hasn't already been included, and safely handles dependencies.

add_action( 'admin_enqueue_scripts', 'wpse8170_enqueue_scripts' );
function wpse8170_enqueue_scripts() {
    wp_enqueue_script( 'wpse8170-admin-js', get_template_directory_uri() . '/admin/admin.js', null, null, true );
}

When in doubt use the function designed to do what you want to do. Reinventing the wheel almost always creates new problems.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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