Site icon Hip-Hop Website Design and Development

WP Plugin: Print javascript in header

[I am new to wordpress programming.]

I am developing a plugin. The plugin needs javascript code in header. In order to print the code only in header of plugin’s setting page. I am unable to do that. I have referred instructions here

The plugin works fine if javascript is printed using this plugin

I also tried to add code within body (after div) by below method….

include( plugin_dir_path( __FILE__ ) . 'ipn/javascript.php');

But that to did not work.

Check the plugin code….

add_action( 'admin_enqueue_scripts', 'my_enqueued_assets' );

function my_enqueued_assets() {
wp_enqueue_script('Google_jquery', 'http://code.jquery.com/jquery-2.2.4.min.js');

}

add_action('admin_menu', 'my_plugin_menu');
function my_plugin_menu() {
add_menu_page('My Plugin Settings', 'Plugin Settings', 'administrator', 'my-plugin-settings', 'my_plugin_settings_page', 'dashicons-admin-generic');
}

function my_plugin_settings_page() {
global $my_plugin_settings;

echo 'HTML Form code here';
add_action( "admin_head-{$my_plugin_settings}", 'my_admin_head_script' );
}
function my_admin_head_script() { ?>




// javascript code that i want to print in header

<script type="text/javascript">$(function() {
var scntDiv = $('#p_scents');
var i = $('#p_scents p').size() + 1;

$(document).on('click','#addScnt', function() {
        $('html code here').appendTo(scntDiv);
        i++;
        return false;
});

$(document).on('click','#remScnt', function() { 
        if( i > 2 ) {
                $(this).parents('p').remove();
                i--;
        }
        return false;
});
});</script>
// javascript code end



<?php }
add_action('admin_head', 'my_custom_fonts');

function my_custom_fonts() {
echo 'CSS style here';
}