Jump to content
create

positioning of custom script.

Recommended Posts

create

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
Danny

Hi,

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


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
create

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
catrina

1. You may need to adjust the z-index: http://www.w3schools.com/cssref/pr_pos_z-index.asp

2. The left/right margins need to be changed: http://www.w3schools.com/css/css_margin.asp

Please see this documentation for further instructions: http://www.pagelines.com/wiki/Custom_CSS


Please read the docs before posting. Please do not private message me unless I ask you to.

Designer | Catrina Dulay

Founder | Catrina and Mouse

Share this post


Link to post
Share on other sites
create

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
evan

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
create

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
Rob

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.


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Similar Content

    • Michael Kummer
      By Michael Kummer+
      Hi guys!
      I have noticed that my primary sidebar becomes intermittently invisible when browsing through various blog articles on michaelkummer.com/blog.
      See:
      https://www.dropbox.com/s/z646sgoa3mfjl1j/Screenshot 2018-07-12 15.57.46.jpg?dl=0 and https://www.dropbox.com/s/vdledzzgginvwgv/Screenshot 2018-07-12 15.57.57.jpg?dl=0
      Upon refresh, the sidebar appears. I have been using the following CSS code to hide the sidebar on mobile without any issues. 
      @media only screen and (max-width: 993px) {
      /* hide sidebars */
           .plsb {
              display: none !important;
          }
      }
      I tried to add the following CSS to force the sidebar to show on screens that are wider than 994 pixels but to no avail. Any clue what could be causing this issue?
    • Michael Kummer
      By Michael Kummer+
      Hi guys!
      I am using the LESS/CSS Pagelines extension and tried to add the following code to make use of FontAwesome:
      a.c2a:before {
          content: "\f07a\00a0";
          font-family: "Font Awesome 5 Pro";
          Font-weight: 900;
          font-style: normal;
          font-weight: normal;
          text-decoration: inherit;
          padding-left: 4px;
      }
       
      The issue is that as soon as I have the CSS via the Custom Styling text box, Pagelines (or the extension) strips out the backslashes (\). As a result, I had to abandon the CSS/LESS extension and instead add all my CSS code to a separate .css file.
      Is there a fix or workaround for this?
      Thanks
      Michael
    • MiraAdmin
      By MiraAdmin+
      Looking for some help on a recently developed issue. Editor will not load. 
      Theme:  DMS2
      Error from:  Chrome - Inspector - console view
      Error message: Refused to execute script from 'http://xxxx.xxx/wp-content/themes/dms/dms/editor/js/gettext.js/?ver=4.9.7' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
      Occurs on all sites on same server. 
      WP versions to 4.9.5, 4.9.6, 4.9.7 = same behavior. Worked properly on these same versions until 07/04/2018.
      No new plugins. Isolating plugins offers same behavior. 
      Server vendor reports no changes, patches, etc. 
      Server re-starts no impact.  

      Thank you. 
    • glyph.marketing
      By glyph.marketing+
      Hello, I am having a problem similar to that experienced by Michael Kummer here. We have pages that show this automatic scrolling issue (examples here and here) and it is sufficiently annoying that we have seen customers bounce while trying to convert. Strangely, it only happens at specific resolutions, so it can be difficult to reproduce. In general we can only consistently reproduce it on a 4k resolution with a browser width between 1517 and 1536px. 
      Thanks to Michael Kummer's help we were able to set the overflow-anchor property to none in the entire body, which fixed the issue as far as we can tell, but also obviously disabled scroll anchoring for the whole site. I tried applying it to the specific element that looked like it was being reloaded, which was the PL Meganav extension, but that was unsuccessful. 
      Can anyone help us figure out which element or ID we can apply this property to, so that we can fix the scrolling issue but not disable scroll anchoring for the entire site?
      Thank you - 
      Glyph Language Services
    • chamois_blanc
      By chamois_blanc+
      Hello,
      Shouldn't the image PL5 component be using the srcset/picture css directives to pick the correct size for an image? or it does already and I don't know how to use it? Thank you for any advice or enlightenment.
×