How to link to a JavaScript file in your BuddyPress child theme

Sep 6, 2010 at 11:25 pm in Advanced Tutorials, BuddyPress by Michael Eisenwasser (Admin) ·

You might want to link to a JavaScript file in your child theme’s directory. You could always hard-code a link to the file, but then if you ever change the name of the theme the link won’t work anymore. It’s better to use a PHP function to automatically call the main child theme’s directory. Unfortunately the normal PHP functions for doing this will always call your BuddyPress Default theme, located in wp-content/plugins/bp-themes/bp-default. Here’s the solution to the problem.

This function will call the root directory of your BuddyPress child theme.

If you are adding a JavaScript file, you should put the file into the following directory: yourtheme/_inc/js/. You will likely need to create the “js” directory. Then call this file using:

[php]
<script src="<?php bloginfo(‘stylesheet_directory’); ?>" type="text/javascript">// <![CDATA[
/_inc/js/file.js">
// ]]></script>
[/php]

Need help with your BuddyPress theme?

Contact us today. We’ll be happy to help.




Leave a reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>