Hello,
I’ve tried my theme with the standard browser of my android mobile phone (I couldn’t check out a name. It’s just called “Browser”) and my whole jquery Code doesn’t work, even my list menu, which I use for mobile devices instead of the navigation bar.
I also tried Dolphin Browser and Boat Browser where it also doesn’t work. But it works with Opera Mobile Browser and Firefox Mobile Browser.
Does anyone have similar experiences?
I load jquery + my jquery file (functions.js) in the functions.php with this code
wp_deregister_script('jquery');
wp_register_script('jquery','http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', '1.7.1', FALSE);
wp_register_script('functionsJS', get_template_directory_uri() . '/js/functions.js', array('jquery'), '1.0', TRUE );
wp_enqueue_script('jquery');
wp_enqueue_script('functionsJS');
The functions.js starts with
$(window).load(function () {
I also tried things like
jQuery(document).ready(function($){
hi,
you say wp_enqueue_script(‘jquery’); Why not name your jquery version “query_custom”. I’m just saying, you could try that.
jayc
yeah, and if you use a custom version of jQuery ain’t you suppose to use $(document).ready(function(){} ?
thanks for help.
I already figured out the problem but haven’t solved it yet.
In the theme options the user can set some options for Nivoslider which I give from PHP to Javascript in the footer.php:
echo "<script type=\"text/javascript\"><!--
var nivoslider_speed = \"".ot_get_option('nivoslider_speed')."\";
var nivoslider_effect = \"".ot_get_option('nivoslider_effect')."\";
</script>"; ?>
In my JS file I call this variables
if ( nivoslider_speed == '' ) { nivoslider_speed=4000; }
$('#slider').nivoSlider({
effect: nivoslider_effect,
pauseOnHover: false,
controlNav: false,
pauseTime: nivoslider_speed
});
But the variables don’t have a value with my mobile browser (I tried it with alert).
Any Ideas how I could fix it? I already had problems with that PHP code in the footer.php before with IE when it was located in the header.php: The whole page was empty. That’s why I put it in the footer
hi,
I dont think you are sending the variable properly, @see documentation around wp_localize_script function.
jayc
I ‘Think’ you should have something like this:
wp_enqueue_script( 'portfolio_js' );
$js_data = array('POST_TYPE'=>$portfolioScreen['post_type']);
wp_localize_script( 'portfolio_js', 'portfolioPHPObj', $js_data );
now you can access the variable in JS like this:
var post_type_name = portfolioPHPObj['POST_TYPE'];
cheers! jayc
^ +1
Also, don’t deregister the WP copy of jQuery if building a commercial theme. I believe that is a rejection reason here, just as it is on WordPress.org.
That’s right. Always use jQuery version that is part of WordPress package or else you can cause incompatibilities with plugins. Also use wp_localize_script() for sending variables to your scripts. This way your code stays clean and you ensure that variables are placed before your script.
- Sold between 250 000 and 1 000 000 dollars
- Community Moderator
- Author was Featured
- Item was Featured
- Bought between 50 and 99 items
- Referred between 1000 and 1999 users
- Has been a member for 3-4 years
- Repeatedly Helped protect Envato Marketplaces against copyright violations
digitalimpact said
^ +1 Also, don’t deregister the WP copy of jQuery if building a commercial theme. I believe that is a rejection reason here, just as it is on WordPress.org.
+50000 that’s what I was about to say
thanks a lot. solved my problem
