• Hi there,
    I’m developing a wordpress plugin and I need to include some js and css files, I’m a little bit confused about using wp-enqueue function, in a case that I’ve used smarty codes inside my page.
    I don’t know where to put these code:

    add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
    function my_scripts_method() {
        wp_enqueue_script(
            'newscript',
            plugins_url( '/js/functions.js' , __FILE__ )
        );
    }

    my plugin pages url are like this:
    http://domain.com/?test=index
    thanks in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • That code can go in the main PHP file of your plugin, or in another file that’s included()‘ed by that file.

    Thread Starter php_1ne

    (@php_1ne)

    You do you mean by main PHP file?
    I’ve put these codes inside my plugin main PHP file, it works fine in wordpress admin page, I mean it loads my js file, but not in my desired page which is like this:
    www.mysite.com/?forum=test
    Should I do something additional?
    I’m sure that main PHP file loads in my desired page, but the function doesn’t work as I wish.
    Any help will be appreciated

    There’s nothing in your code that would suggest that it shouldn’t be right. You need to do some basic de-bugging. First step is to add echo statements around to see what does, and doesn’t happen.

    eg:

    add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
    echo 'Added JS action call...';
    function my_scripts_method() {
        echo 'Set up JS files...';
        wp_enqueue_script(
            'newscript',
            plugins_url( '/js/functions.js' , __FILE__ )
        );
    }

    That will tell you if things are actually happening.

    The next thing to do is check your browser developer console, like FireBug etc. That way you will see if you’re calling an invalid URL for your JavaScript file.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘where to use wp-enqueue in plugin?’ is closed to new replies.