Hello,
I have the following code in my functions.php file. It takes the javascript and adds it into the footer. Seemed to be working fine, but a user is claiming it's producing an error on their end. Just looking for someone to find what could be the issue!
Here is part of the code I believe is causing the error.
//Include Scripts
add_action('init', 'ok_theme_js');
function ok_theme_js() {
if (is_admin()) return;
//jQuery Via Google
wp_deregister_script( 'jquery' );
wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"), false, '1.3.2', true);
wp_enqueue_script( 'jquery' );
//Pretty Photo
wp_enqueue_script('pretty_photo_js', get_stylesheet_directory_uri() . '/includes/js/jquery.prettyPhoto.js', false, false , true);
}
//Add Javascript To Footer
add_action('wp_footer', 'print_my_script');
function ok_footer_scripts() { ?>
<script type="text/javascript">
/* <![CDATA[ */
var J = jQuery.noConflict();
J(document).ready(function(){
//Lightbox
J("a[rel^='prettyPhoto']").prettyPhoto({theme: 'light_square'});
//Portfolio hover
J(".ad img, .portfolio-large img").hover(
function() {
J(this).animate({"opacity": ".8"}, "fast");
},
function() {
J(this).animate({"opacity": "1"}, "fast");
});
//Portfolio hover
J(".fade img, .portfolio-items4 li a, .portfolio-items li a, .single-large img, .portfolio-item-third img, .portfolio-items2 a, .portfolio-item-third a, .blog-content h3 a").hover(
function() {
J(this).animate({"opacity": ".8"}, "fast");
},
function() {
J(this).animate({"opacity": "1"}, "fast");
});
//Removes the margin of the portfolio items on the furthest right side of the page. Let's you achieve a full-width portfolio.
J(".portfolio-items > li:nth-child(5n)").addClass('removemargin');
J(".portfolio-items2 > li:nth-child(2n)").addClass('removemargin');
J(".portfolio-items4 > li:nth-child(3n)").addClass('removemargin');
J(".portfolio-item-half .portfolio-items > li:nth-child(2n)").addClass('removemargin');
J(".portfolio-row > li:nth-child(5n)").addClass('removemargin');
J("div.columns > div:nth-child(4n)").addClass('remove-border');
J('<div style="clear:both;"> </div>').insertAfter('.content-full ul li:nth-child(3n)');
J('<div style="clear:both;"> </div>').insertAfter('.portfolio-items4 li:nth-child(3n)');
J('<div style="clear:both;"> </div>').insertAfter('.portfolio-items > li:nth-child(5n)');
});
/* ]]> */
</script>
And this is the error it is producing:
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'print_my_script' was given in /home/badreef/public_html/wp-includes/plugin.php on line 405
Utkarsh Kukreti answers:
That part isn't causing the error. Please search for "print_my_script" in your files, and paste the code around that.
Mike McAlister comments:
Whoops! I meant to post the whole snippet actually. There it is.
Mike
Utkarsh Kukreti comments:
add_action('wp_footer', 'print_my_script');
should be
add_action('wp_footer', 'ok_footer_scripts');
Mike McAlister comments:
Perfect, that'll do it! Thanks Utkarsh!
Mike
Eddie Moya answers:
You dont seem (at least in this snippet) to have a function called 'print_my_script'. That string is sometimes used as an example for enqueueing javascript. It this is not being used here, remove it, otherwise check if there is typo or something. There should be a function called print_my_script()