I have asked this in the WP forums, but it seems no one has answered :)

I have come across quite a few discussions about this, but couldn't solve it myself as of yet.. :(

I have the following simple script executing on different pages of my choice:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="wp-content/custom/jquery.backstretch.min.js"></script>
<script type="text/javascript">$.backstretch("wp-content/themes/photoshot/images/home_bg.jpg", {speed: 1000});</script>

It simply is for background image scaling.

However, since my Front Page is not really a page, I can't embed the code as I have been in other pages, as there is no 'page ID' for the front page (or if there is I have no clue).

Either way, could someone please give me a copy-paste solution, and indication where to insert the necessary php code so that the above script is executed on the front page only (which is set to display recent posts)?

Thanks very very much!

4 answers

1
point
This was chosen as the best answer

This is a stab in the dark and not the optimum solution, but in your theme's header.php file just after the line with wp_head();

insert the following:

if ( is_front_page() )

echo '<script type="text/javascript" src="wp-content/custom/jquery.backstretch.min.js"></script>
<script type="text/javascript">$.backstretch("wp-content/themes/photoshot/images/home_bg.jpg", {speed: 1000});</script>';

It should work, but it is so wrong.

But then so is using the plugin you refer to to add another call to jQuery.

You need someone expert to modify your theme I think.

Answered about 6 years ago by Tony Crockford
0
points

you need is_front_page() but I can't tell you how to use it without seeing the rest of your code.

Scripts should also be included using wp_enqueue and by the look of what you're doing you're in danger of loading two versions of jQuery, as WP loads its own.

Check your source code, and have a look at is_front_page()

Answered about 6 years ago by Tony Crockford
0
points

Thanks for the response.

For now, I am using this plugin to laod scripts into the head or footer of each individual page: http://wordpress.org/extend/plugins/hifi/

I am not certain whether it loads properly via wp_enqueue or not..

I am a beginner. Although I have come across teh is_front_page() function, I am not sure where to begin. Any more help is appreciated. Thanks again.

Answered about 6 years ago by vulgarbulgar
0
points

It worked! Thanks. However, I had to load jQ as well by adding the follwoing:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

As you said, any ideas on how to ensure jq isn't loaded twice,a d the script is loaded properly via wp_enqueue?

You have been very helpful. I did get the functionality I was seeking. This is just above and beyond, but something which definitively would help page loading.

Thanks.

The site is here.

Answered about 6 years ago by vulgarbulgar