That's how I connect js and css

function bankadata_include_js() { wp_enqueue_script( 'myscript1', 'assets/js/main_slider.js', array('jquery') ); wp_enqueue_script( 'myscript2', 'assets/js/second_slider.js', array('jquery') ); } function bankadata_include_css() { wp_enqueue_style('my-styles-1', plugins_url("assets/css/style.css", __FILE__)); wp_enqueue_style('my-styles', "https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"); } add_action('wp_enqueue_scripts','bankadata_include_js'); add_action('wp_enqueue_scripts','bankadata_include_css'); 

Slider code itself

 $(document).ready(function(){ $('.tabs_menu a').click(function(e){ e.preventDefault(); $('.tabs_menu .active').removeClass('active'); $(this).addClass('active'); var tab = $(this).attr('href'); $('.tab').not(tab).css({'display':'none'}); $(tab).fadeIn(400); }); }); 

The script itself, without inserting into wp the plugin works as it should. CSS and HTML code pastebin.com/VQXi8FZy

  • one
    What is the problem? What do you want to do that does not work? Some kind of error in the console? Telepaths sometimes drop in here, but not very often. - Duck Learns to Take Cover
  • Just do not change the slides. CSS and HTML code pastebin.com/VQXi8FZy There are no assumptions why it doesn't work, because without integration into WP everything is ok. - Hardc0re
  • Ok, it looks really like some kind of specific wordpress problem, and I did not work with WordPress in life. First we localize the problem. Check first of all whether the script is added to html, zagenerenny engine (the problem is that it does not work), or not added at all (not connected). - Duck Learns to Take Cover

1 answer 1

Most likely the problem is in this connection scripts

 function bankadata_include_js() { wp_enqueue_script( 'myscript1', 'assets/js/main_slider.js', array('jquery') ); wp_enqueue_script( 'myscript2', 'assets/js/second_slider.js', array('jquery') ); } 

The second argument for the wp_enqueue_script() function is the relative path. As a result, the path to your script will look like http://your_site.comassets/js/main_slider.js , which is clearly an error because there is no slash after the first-level domain. If the folder with scripts is in the folder of your plug-in, use the plugins_url() function to generate the correct url , or put a slash before the assets , if this directory is in the root of the site. That is either

 wp_enqueue_script('myscript1', plugins_url('assets/js/main_slider.js', __FILE__), array('jquery')); 

or

 wp_enqueue_script('myscript1', '/assets/js/main_slider.js', array('jquery')); 
  • "As a result, the path to your script will look like your_site.comassets / js / main_slider.js " - this line confuses me a little. I did not work with WordPress in my life, but did he really stick this way? I would expect him to understand the line without the initial slash as a relative path for something and would be something like "relative root" /assets/js/main_slider.js; Although maybe he is really so stupid, you never know - Duck Learns to Take Cover
  • one
    Well, it's not that stupid, it just works that way) and yes, that is what it will stick together, tested more than once - alenkins