Call a javascript function from another file

The issue you have is that Slider is not accessible outside of its scope as that’s defined by the .ready() though you’ve used shorthand for that. The function needs to be available in the global scope: file1.js function Slider() { this.nb_ele = 10; } jQuery(function($) { // … }); file2.js jQuery(function($) { var slider = … Read more

Create shortcode to echo javascript

First of all, it looks like you are trying to enqueue version 2.2.4 of jquery, under the condition that jquery has already been loaded. That doesn’t look good. Secondly, you can’t just echo a script in a shortcode. You must add it to another script using wp_add_inline_script. Like this: function wpse238227_custom_shortcode23() { wp_enqueue_script(‘script-typed’, ‘https://www.example.comwp-content/themes/mediso-v1-03/typed.js’, array(‘jquery’)); … Read more

Ajax submit comments

you might find these links handy if you’re going to code it yourself http://byronyasgur.wordpress.com/2011/06/27/frontend-forward-facing-ajax-in-wordpress/ http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/ I am fairly sure your URL is wrong url: “../wp-comments-post.php” – ajax in wordpress has to be sent (quite strangely) to/through admin-ajax.php (even if it’s not on the admin side). If you read the first link it is explained in … Read more

Would to use AJAX to get an option from the database and use it in a jquery setup or is there an alternative to consider?

Enqueue the script as you would normally, & then call the JS function right after the slider HTML output (or on wp_footer), and pass a JSON config back to the function. <!– slider HTML –> <script type=”text/javascript”> jQuery( “#my_slide” ).mySlider( <?php echo json_encode( $my_config /* array or object of arguments */ ) ?> ); </script> … Read more

How to isolate code to the post edit screen

Use the WP_Screen object to tell where you are at in the admin instead. Much more convenient. $screen = get_current_screen(); if ( $screen->id == ‘edit-post’ ) { // you’re on the posts screen } Note that you have to wait until at least the admin_head hook to run for the current screen to have been … Read more

Plugin – Make sure jquery is loaded in my settings page plus my JS file

First use add_options_page() – shorter wrapper, better practice. Second you need to save its return in some (global or static) variable. That is often used thingie and confusingly referenced by different names in documentation. Global $hook_suffix holds such value for current page. function create_admin_pages() { global $my_page; $my_page = add_options_page(… From there it is something … Read more

wp_dequeue_script not working in my plugin

wp_enqueue_script() also registers the script. So, you’ll also need to de-register it first. This code should work depending on how and where the script is enqueued. function my_dequeue() { wp_deregister_script( ‘ocmx-jquery’ ); wp_dequeue_script( ‘ocmx-jquery’ ); } add_action( ‘admin_enqueue_scripts’, ‘my_dequeue’, 10 ); You might also need to play with the priority of the action.

How to enqueue jquery in admin and why is it not already there?

First, check for syntax errors. The syntax highlighting seems to indicate that you have syntax errors. Second, don’t wrap your add_action() calls inside conditionals; rather, wrap your callback function content inside the conditionals, e.g.: <?php function theme_upgrade_alernt() { if ( is_admin() && $pagenow == ‘theme-install.php’ && $_GET[‘tab’]==”upload”){ // CODE GOES HERE } else { // … Read more