• i want to create tool using js script in WordPress.

    I am able to enqueue script and style sheet but my doubt is how do i defined the loading location of my script . Because of that script my tool will load in frontend. but where it will load how do i defined the position in a page.

    I want that script to load between content or after title of the page.

    Feature i needed.

    1. should load via my plugin
    2. should load only on page no xyz
    3. and should load between or exact defined position in a page.
    4. I am not a coder so please guide me i tried everywhere couldn’t be able to find how to define location of loading
Viewing 1 replies (of 1 total)
  • Hi, I will give you an example to how to do it with shortcode:

    I suggest you copy the code into a code editor for proper formatting so you can read it and understand what it does

    // Callback function for our shortcode
    function loadPluginScript(){	
    	// Load the script, first parameter is the "handle" aka name of the script, it should be unique
    	// Second parameter is the plugin url, the function plugins_url takes the path to the plugin via __FILE__ and then adds the first parameter to it
    	// So if you have the folders /assets/js/ in your plugin main folder you should do it like this
    	wp_enqueue_script('my-script-name', plugins_url('assets/js/your-script.js', __FILE__));
    }
    // Add shortcode that calls the above defined function
    // You can add the shortcode anywhere like this in a shortcode field [loadScript] the name is the first parameter, the second is the name of the function that the shortcode executes
    add_shortcode('loadScript', 'loadPluginScript');
    • This reply was modified 3 years, 2 months ago by Benedikt Ledl.
Viewing 1 replies (of 1 total)

The topic ‘script loading’ is closed to new replies.