I’m trying to create and test my first basic WP plugin with some difficulty. I am also running a WAMP server.

Below are the scripts utilized.

The html is the only script added to a page through WP’s page edit window.
The php is from a file (whose content can also be seen through the Plugin edit window within WP) saved in the plugin/test_plugin directory.
The javascript is saved in a file within the same test_plugin directory as the php file.

Side notes:

The plugin has been “activated” in the main WP Plugin window.
Identical (except for file storage locations, names, script name, etc.) have been previously inserted into the theme’s function.php file along with associated js files being made available that HAVE demostrated the desired feature.

What am I doing wrong??

html

<button id="unique_button" type="button">Click Me!</button>

test_plugin.php

<?php
    /*
    Plugin Name: test_plugin
    */

 function test_plugin() {
    wp_enqueue_script( 'change_button', get_template_directory_uri() .  'change_button.js', array( 'jquery' ), '1.0.0', 1 );
}

add_action( 'wp_enqueue_scripts', 'test_plugin' );

?>

change_button.js

jQuery( function ( $ ) {
    $("#unique_button").click(function() {
        $(this).fadeOut(1000);
    })
});

Read more here: Trouble with very basic plugin creation


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: