Archived

This topic is now archived and is closed to further replies.

  • 0

positioning of custom script.


Question

Posted · Report post

Take a look at my site http://tinyurl.com/cosv8ge

I'm trying to change the position of a custom script that I installed into the header scripts. The script displays a custom greeting on the site depending on the time of day. I want the greeting to be above the telephone number in the header but i'm struggling to achieve this.

The script is as follow:


<span class="xdate"><?php echo date('l jS F Y'); ?></span>

<script language="Javascript" type="text/javascript">

<!--

var day = new Date();

var hr = day.getHours();

if (hr <= 11)

   {

   document.write("Good Morning...");

   }

else if (hr > 11 && hr < 17)

   {

   document.write("Good Afternoon...");

   }

else

   {

   document.write("Good Evening...");

   }


//-->

</script>

Can anyone help?

thanks

James UK

Share this post


Link to post
Share on other sites

7 answers to this question

Posted · Report post

Scripts that output stuff for display on the page like this really don't belong in the headerscripts as it will output in the <head> tag. You're better off adding this code with a php hook in your child theme's functions.php file.


<?php

add_action('pagelines_inside_top_branding', 'branding_greeting');

function branding_greeting() {

?><div id="custom_greeting">

<script type="text/javascript">

<!--

var day = new Date();

var hr = day.getHours();

if (hr <= 11)

	 {

	 document.write("Good Morning...");

	 }

else if (hr > 11 && hr < 17)

	 {

	 document.write("Good Afternoon...");

	 }

else

	 {

	 document.write("Good Evening...");

	 }


//-->

</script>

</div>

<?php

}

That will get you a lot closer to where you want it, and then you won't need such hardcore CSS to wrestle it into place.

Hope that helps :)

Share this post


Link to post
Share on other sites

Posted · Report post

Hi Evan, thanks for your reply.

I added your code to the functions.php file located in /wp-content/themes/pagelines/functions.php

and was returned with the following error when I reloaded the page...

Parse error: syntax error, unexpected '<' in /websites/123reg/LinuxPackage22/ll/oy/ds/lloydspropertyagents.com/public_html/wp-content/themes/pagelines/functions.php on line 24

Any ideas?

thanks

J

Share this post


Link to post
Share on other sites

Posted · Report post

thanks for the replies, I have managed to position the div on top now with an outlandish z-index figure of 999. I'm still having trouble with positioning the div above the phone number in the header. The margins seem to be working off the edge of the browser window rather than the edge of the web pages? any ideas how i define that??

Share this post


Link to post
Share on other sites

Posted · Report post

Hi,

You would need to wrap in a div to position it however, Javascript isn't really my forte.

Share this post


Link to post
Share on other sites

Posted · Report post

Evan didn't point you to the correct functions.php. Please remove the code from where you placed it.

The code he provided should work if you have the pagelines-customize plugin installed. In there, you'll find a functions.php. Just tack his code at the end.

Alternatively, if you're using a child theme, like Base, you can use the functions.php inside the child theme folder.

You'll get errors when using the core files.

Share this post


Link to post
Share on other sites

Posted · Report post

I have managed to wrap it in a div, but i'm struggling to:

1. bring the div to the front, so it sits on top of the header

2. It's currently set to 50px off the right but its doing this off the side of the browser window, rather than the right hand side of the web page

grateful for any help

Share this post


Link to post
Share on other sites