whenever i use a static background that requires stretching i use http://srobbin.com/jquery-plugins/backstretch/ it works in ie, which versions im not sure
Thanks. I’ve never implemented jQuery before, but I may resort to learning it if I can’t figure this out.
D
its quite easy, wp_register_script wp_enqueue_script
will be what your looking for
I have no idea what that means :). I am rather new to this, I’m afraid.
alright well here, your code should look like this
function backstretch_script() {
wp_register_script( 'backstretch', get_stylesheet_directory_uri() . '/_inc/js/backstretch.js', 'jquery', '1.8.3', true);
wp_enqueue_script( 'backstretch' );
}
add_action( 'wp_enqueue_scripts', 'backstretch)script' );
the get_stylesheet_directory_uri refers to where you’ve put backstretch.js, so you may need to change that. Once you’ve added that code you can then use wp_footer(); to use the plugin like so
function backstretch_add() {
?>
<script type="text/javascript">
jQuery.backstretch("<?php echo get_stylesheet_directory_uri()?>/_inc/images/background.jpg");
</script>
<?php
}
add_action ('wp_footer', 'backstretch_add', 20);
note – you’ll have to change the code between “” to use your image
hope that helps @diabolique65
Matt, thanks very much. That’s good of you. I’m afraid this is over my head, though. Can you point me to an online tutorial that can give me the basics before I attempt this myself?
No need…. I’ll just explain it slightly better you’re using a buddypress child theme, so you need to create a folder inside _inc called “js”. For me, this holds all my javascript files in this case, you’ll put backstretch.js here (make sure the name is backstretch.js)
Next step is putting the background image in the folder _inc as well, place your image inside “images” within _inc, name it background.(whatever)
Now we need to add the code so that wordpress uses these files – we can add it to our functions.php
function backstretch_script() {
wp_register_script( 'backstretch', get_stylesheet_directory_uri() . '/_inc/js/backstretch.js', 'jquery', '1.8.3', true);
wp_enqueue_script( 'backstretch' );
}
add_action( 'wp_enqueue_scripts', 'backstretch_script' );
function backstretch_add() {
?>
<script type="text/javascript">
jQuery.backstretch("<?php echo get_stylesheet_directory_uri()?>/_inc/images/background.jpg");
</script>
<?php
}
add_action ('wp_footer', 'backstretch_add', 20);
add that code as is – you may want to change the .jpg to .png or whatever file type your image is.
If for some reason you don’t want to place backstretch.js or your background image in those folders, you’ll need to modify these two lines to the new location.
wp_register_script( 'backstretch', get_stylesheet_directory_uri() . '/_inc/js/backstretch.js', 'jquery', '1.8.3', true);
jQuery.backstretch("<?php echo get_stylesheet_directory_uri()?>/_inc/images/background.jpg");
Hopefully that’s slightly clearer
Thank you so much!
Where does this code go?:
wp_register_script( 'backstretch', get_stylesheet_directory_uri() . '/_inc/js/backstretch.js', 'jquery', '1.8.3', true);
jQuery.backstretch("<?php echo get_stylesheet_directory_uri()?>/_inc/images/background.jpg");
those two lines were “IF” you changed the locations of the javascript file and the image – if you placed them in the folders that i mentioned, you won’t need to modify those lines at all
Very good. I’ll try this tomorrow and let you know.
Cheers,
D
It worked!
Thank you very much, Matt!
Cheers,
Dima
Appreciate all your help!