adding jquery ui to wordpress site - wordpress

I would like to use http://jqueryui.com/dialog/ on my wordpress site but I can't figure out how to add it.
I created a file Chameleon/js/popup.js with the code:
jQuery(document).ready(function($) {
$( "#dialog" ).dialog();
});
Then I added to functions.php
add_action( 'wp_enqueue_scripts', 'add_my_script' );
function add_my_script() {
wp_enqueue_script(
'popup', // name your script so that you can attach other scripts and de-register, etc.
get_template_directory_uri() . '/js/popup.js', // this is the location of your script file
array(' <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">') // this array lists the scripts upon which your script depends
);
and in my post template I added the code:
<div id="dialog" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
but it doesn't work.

add path as like this
add_action( 'wp_enqueue_scripts', 'add_my_script' );
function add_my_script() {
wp_enqueue_style( 'themeslug-jquery-css', '//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css' );
wp_enqueue_style( 'themeslug-stylesheet', get_template_directory_uri.'/resources/demos/style.css' );
wp_enqueue_script( 'themeslug-popup', get_template_directory_uri() . '/js/popup.js', array('jquery'), '' );
wp_enqueue_script( 'themeslug-jquery-main', '//code.jquery.com/jquery-1.10.2.js', array('jquery'), '' );
wp_enqueue_script( 'themeslug-jquery-ui', '//code.jquery.com/ui/1.11.2/jquery-ui.js', array('jquery'), '' );
}

Related

wp_enqueue_script - Additional Jquery Does Not Appear in Source Code

I am able to put bootstrap.min.js with dependency on the native wordpress jquery, but Jquery 1.11.1 does not appear in the source code and Font Awesome also does not work correctly
I've tried some code from other questions in stackoverflow, but I still can not resolve my question
I put some comments in the code below:
UPDATED CODE
function enqueue_jquery() {
// deregister jquery ok
wp_deregister_script('jquery'); // unregister the WP-provided jQuery version
// tag is not added in code
wp_enqueue_script(
'jquery',
get_template_directory_uri() . '/js/jquery.js',
array(), // don't make jquery dependent on jquery...!
'1.11.1',
true
);
}
add_action('wp_enqueue_scripts', 'enqueue_jquery');
function enqueue_styles_scripts() {
//its OK
wp_enqueue_style(
'style-theme',
get_stylesheet_uri(),
array('bootstrap-css')
);
//its OK
wp_enqueue_style(
'bootstrap-css',
get_template_directory_uri() . '/css/bootstrap.min.css'
);
//its OK
wp_enqueue_style(
'stylish-portfolio',
get_template_directory_uri() . '/css/othercss.css'
);
//I changed the directory of the files to css and fonts folders and it worked correctly
wp_enqueue_style(
'font-awesome',
get_stylesheet_directory_uri() . '/css/font-awesome.css'
);
//Appears in header but is working correctly
wp_enqueue_script(
'bootstrap-js',
get_template_directory_uri() . '/js/bootstrap.min.js',null
);
}
add_action('wp_enqueue_scripts', 'enqueue_styles_scripts');
//Its Ok
function wpse_ie_conditional_scripts() { ?>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<?php
}
add_action( 'wp_head', 'wpse_ie_conditional_scripts' );
?>
So the problem is that 'jquery' is already registered and queued by WP. What I have done in the past is first unregister the WP-provided jquery, and then enqueue my own version. WARNING: test this out thoroughly, because you will now be upgrading jQuery for the whole WP installation!
wp_deregister_script('jquery'); // unregister the WP-provided jQuery version
wp_enqueue_script(
'jquery',
get_template_directory_uri() . '/js/jquery.js',
array(), // don't make jquery dependent on jquery...!
'1.11.1',
true
);
Alternatively, you could load a second version of jQuery in no-conflicts mode, but that is not a really good idea...
Hope this helps!
I was able to resolve without using function to unregister the native wordpress jquery and register my theme jquery
//Without using function
wp_deregister_script('jquery');
wp_register_script('jquery', get_template_directory_uri() . '/js/jquery.js', false, '1.11.1');
wp_enqueue_script('jquery');
function enqueue_styles_scripts() {
//its OK
wp_enqueue_style(
'style-theme',
get_stylesheet_uri(),
array('bootstrap-css')
);
//its OK
wp_enqueue_style(
'bootstrap-css',
get_template_directory_uri() . '/css/bootstrap.min.css'
);
//its OK
wp_enqueue_style(
'stylish-portfolio',
get_template_directory_uri() . '/css/othercss.css'
);
//its OK
wp_enqueue_style(
'font-awesome',
get_stylesheet_directory_uri() . '/css/font-awesome.css'
);
//its OK
wp_enqueue_script(
'bootstrap-js',
get_template_directory_uri() . '/js/bootstrap.min.js',null
);
}
add_action('wp_enqueue_scripts', 'enqueue_styles_scripts');
//Its Ok
function wpse_ie_conditional_scripts() { ?>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<?php
}
add_action( 'wp_head', 'wpse_ie_conditional_scripts' );
?>

Leaflet map does not display on wordpress page

After switching to storefront theme leaflet map has disappeared.
link how it looks
functions.php
add_action( 'wp_enqueue_scripts', 'enqueue_parent_theme_style' );
function enqueue_parent_theme_style() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
/* wp_enqueue_style( 'bootstrap', 'http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css' ); */
wp_enqueue_style( 'leaflet.css','http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css');
}
function theme_scripts(){
wp_enqueue_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js', array('jquery'), '1.12.2', false);
wp_enqueue_script('bootstrap-js', 'http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js', array('jquery'), false);
wp_enqueue_script('leaflet.js', 'http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js' ,false);
wp_enqueue_script('main.js', get_template_directory_uri(). '/js/main.js');
}
add_action( 'wp_enqueue_scripts', 'theme_scripts' );
Bootstrap is commented because it breaks website view (it becomes smaller). But without commenting map is not working nevertheless.
I have added link to the map page. I dot not know is it proper way.
<link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_directory_uri() ; ?>/css/bootstrap.min.css">
<script type="text/javascript" src="<?php echo get_stylesheet_directory_uri() ; ?>/js/main.js"></script>
You must have following javascript instruction to create a map
var map = L.map('mapid').setView([latitude, longitude], zoom);
See documentation
If you are using a Wordpress plugin, you should refer to its documentation
A look into the console would have been useful:
TypeError: $ is not a function
Change in main.js this line:
$( document ).ready(function() {
to
jQuery( document ).ready(function($) {

Can't load script when using wp_enqueue_script

I'm trying to use a script called show_post.js on my Wordpress site. I've successfully loaded it directly in header.php:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript" src="wp-content/themes/tutorial_theme/scripts/show_post.js"></script>
However, when I'm trying to do it via functions.php and wp_enqueue_script it won't work. Here is my functions.php file:
<?php function wpdocs_scripts_method() {
wp_enqueue_script('show_p', '/wp-content/themes/tutorial_theme/scripts/show_post.js', array( 'jquery' ));
}
add_action( 'wp_enqueue_scripts', 'wpdocs_scripts_method' );
?>
What am I doing wrong here?
Add Script like
wp_enqueue_script('show_p',get_template_directory_uri().'/scripts/show_post.js', array( 'jquery' ));
Try this:
function theme_enqueue_scripts() {
wp_register_script("show_p", get_template_directory_uri() . '/scripts/show_post.js', array('jquery'));
wp_enqueue_script('show_p');
}
add_action('wp_enqueue_scripts', 'theme_enqueue_scripts');

Wow.js on WordPress loading some animations on page load and others not at all

I'm trying to use wow.js on my WordPress site and I've been through a handful of forums about similar issues but I can't seem to get it working. The site of icons on top I believe are loading on the page load not scroll and further down on the page (under the green band) I have an h2 that never loads at all when scrolling down to it. (The animated class is added, but element is hidden and no animation occurs).
My html:
<h1 class="wow animated fadeInRight left">A website must perform many
functions.</h1>
In functions.php
function sk_enqueue_scripts() {
wp_enqueue_style( 'animate', get_stylesheet_directory_uri() . '/js/animate.css' );
wp_enqueue_script( 'wow', get_stylesheet_directory_uri() . '/js/wow.js', array(), '', true );
}
add_action( 'wp_enqueue_scripts', 'sk_enqueue_scripts' );
//* Enqueue script to activate WOW.js
function sk_wow_init_in_footer() {
add_action( 'print_footer_scripts', 'wow_init' );
}
add_action('wp_enqueue_scripts', 'sk_wow_init_in_footer');
//* Add JavaScript before </body>
function wow_init() { ?>
<script type="text/javascript">
new WOW().init();
</script>
<?php }
add_action('wp_head', 'wow_init');
Thanks in advance!
You have an error:
Uncaught ReferenceError: WOW is not defined
...because you're enqueueing wow.js in the footer, and are trying to use WOW in the head.
Been searching for a while.. trying different suggestions. Finally got it working following this tutorial.
http://www.jeremycookson.com/how-to-add-scrolling-animations-in-wordpress/
Here is the code I replaced in my functions file.
//* Enqueue Scripts
function sk_enqueue_scripts() {
wp_enqueue_script( 'myscripts', get_stylesheet_directory_uri() . '/js/scripts.js', array(), '', true );
wp_enqueue_script( 'wow', get_stylesheet_directory_uri() . '/js/wow.js', array(), '', true );
wp_enqueue_style( 'animate', get_stylesheet_directory_uri() . '/js/animate.css');
}
add_action( 'wp_enqueue_scripts', 'sk_enqueue_scripts' );
//* Enqueue script to activate WOW.js
function sk_wow_init_in_footer() {
add_action( 'print_footer_scripts', 'wow_init' );
}
add_action('wp_enqueue_scripts', 'sk_wow_init_in_footer');
//* Initial Wow before body </body>
function wow_init() { ?>
<script type="text/javascript">
new WOW().init();
</script>
<?php }
I'm not sure what changed other than I moved my scripts.js file to be enqueued as well, when previously I was manually loading it in footer.php
*****UPDATE I also noticed that removing
html,body{height:100%;}
may have made a difference in WOW determining when the animation was in view.**

Why wp_enqueue_style and wp_enqueue_script was called incorrectly?

I am trying to develop a Wordpress plugin. I have added style and script in following way
add_action( 'wp_enqueue_scripts', 'newsbox_style_and_script' );
function newsbox_style_and_script()
{
wp_enqueue_style( 'bootstrap-style', plugins_url( '/css/bootstrap.min.css', __FILE__ ),array(),'3.0.3');
wp_enqueue_style( 'bootstrap-theme-style', plugins_url( '/css/bootstrap-theme.min.css', __FILE__ ),array(),'3.0.3');
wp_enqueue_style( 'site-style', plugins_url( '/css/site.css', __FILE__ ));
// Register the script like this for a plugin:
wp_enqueue_script( 'newsbox-script', plugins_url( '/scripts/jquery.bootstrap.newsbox.min.js', __FILE__ ),array("jquery"), '1.0.1', true );
}
But it is showing the following error
Notice: wp_enqueue_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks.
I have checked this WP_debug errors with wp_enqueue . But can't solve the problem. Please tell me the solution.
UPDATE:
errors are showing for following code
wp_head();?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(".demo2").bootstrapNews({
newsPerPage: <?php
if($display_options[ 'news_per_page' ]){
echo $display_options[ 'news_per_page' ];
}
else{
echo 4;
}
?>,
autoplay: true,
pauseOnHover: true,
navigation: false,
direction: 'down',
newsTickerInterval: <?php
if($display_options[ 'news_Ticker_Interval' ]){
echo $display_options[ 'news_Ticker_Interval' ];
}
else{
echo 2500;
}
?>,
onToDo: function () {
//console.log(this);
}
});
});
</script>
Would you please tell me where is the problem of this code?

Resources