you can use bb_get_location()
like
if ( bb_get_location() == ‘login-page’ {
your jquery script
}
Maybe I wasn’t clear – basically I have a script that I wrote myself that I have put in header.php so that it gets loaded on every page. However, this script needs the jquery script to load as well or it won’t work. BBPress has jquery built-in but it only loads it on certain pages. I wanted to see what defines where the jquery script that is built into BBpress is called…
But I can use this technique to do the same thing, just the opposite way around, so thanks for the help! I did it like this:
<?php if ( in_array( bb_get_location(), array( 'login-page', 'register-page' ) ) ) echo "<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'></script>n"; ?>
I tried to use bb_enqueue_script( 'jquery' );
in there but couldn’t get that to work!
<?php bb_enqueue_script(‘jquery’); ?>
> I tried to use bb_enqueue_script( ‘jquery’ ); in there but couldn’t get that to work!
You *need* to get it to work, that’s the proper way of doing it. You should figure out what you were doing wrong.
Check this micro-plugin. It loads jquery in every page.
<?php
/*
Plugin Name: jQuery please
Plugin URI: http://www.the.url.com
Description: I really need jQuery
Version: 1.0
Author: Me
Author URI: http://www.the.url.com
*/
add_action('bb_init', 'jquery_please_initialize');
add_action('bb_head', 'jquery_please_js', 100);
function jquery_please_initialize()
{
bb_enqueue_script('jquery');
}
function jquery_please_js()
{ ?>
<script type="text/javascript">//<![CDATA[
// Your script goes here
//]]></script>
<?php
}
?>
You put on the “jQuery please” tag?
thanks for the input guys. The only thing I was worried about was it would be loading jquery on every page, even when it won’t be used – or do you think it’s not a large enough file to worry about?
It’s not a big deal. You can change the plugin in order to prevent the inclusion of jQuery on those pages that you know that will not need the special treatment. Change line:
add_action('bb_init', 'jquery_please_initialize');
with:
// Add here all the template files that need special treatment
add_action('bb_topic.php', 'jquery_please_initialize');
add_action('bb_edit-post.php', 'jquery_please_initialize');
// et cetera
cool, thanks zaerl – I had it working before but your solution is much more elegant!
May I suggest another solution? bb_enqueue_script()
is deprecated, you should first check if script is already included using wp_script_is()
and then call wp_enqueue_script()
.
add_action( 'bb_init', 'enqueueJQuery' );
function enqueueJQuery() {
if ( !wp_script_is( 'jquery' ) )
wp_enqueue_script( 'jquery' );
}