Current year script footer

Hi,

What’s the best way to add current year script to a footer container?

J

Hey,

You add your custom script like:

add_action( 'wp_footer', 'adding_scripts_to_footer', 10 );

function adding_scripts_to_footer(){
   echo " // INSERT YOUR CODE HERE! ";
}

Thanks John,

Can you also tell me what kind of element to put it in?

If I put it in a text element, it just shows the code.

J

Hi there,

Please try the Javascript code in a Raw Content element.

Hope this helps.

Thanks Jade.

I don’t have an element called Raw Content.

I put the script into a Content Area element and it displays the code.

J

Hi There,

Actually you can put the JavaScript Snippet on a Text element.

However, that will broke the builder preview. So we can not recommended that. For now there is no element on the Header and Footer builder where you can put an inline script.

Instead you can use the php code provided by John above to hook the script below the footer.

add_action( 'wp_footer', 'adding_scripts_to_footer', 10 );

function adding_scripts_to_footer() { ?>
<div class="x-container max width">
  &copy; 2010<script>new Date().getFullYear()>2010&&document.write("-"+new Date().getFullYear());</script>, Company.
</div>

<?php }

You can add that on your Child theme’s functions.php file.

Thank you.

Thanks, that works.

Is there a way to put it in the footer?

Hello There,

If you want to add it in your footer builder > content area, you can simply insert this code:

<div class="x-container max width">
  &copy; 2010<script>new Date().getFullYear()>2010&&document.write("-"+new Date().getFullYear());</script>, Company.
</div>

Hope this helps. Please let us know how it goes.

Thank you.

That code overwrites the rest of my footer and displays “-2017” in the top left corner of the footer.

Here’s what I’m trying to achieve using a typekit font

J

Hi,

Would you mind providing us with login credentials so we can take a closer look? Please provide following information:

Set it as Secure Note

  • Link to your site
  • WordPress Admin username / password
  • FTP credentials

All the best!

Thanks Paul.

Info attached.

Footer is labeled “Current year script test” and here’s what I’m seeing https://ibb.co/mz2ic5

J

Hi,

I added a class(copyright) to your text element in your footer.

To add the dynamic Year, you can add the code below in Footer Builder > JS

jQuery(function($) {
    var $Year = new Date().getFullYear()
    $('.copyright').html('<span>© '+$Year+' DANGER PRESS LLC</span>');
});

Hope that helps.

1 Like

Thanks Paul.

I used the Content Area code to keep it inside the footer

`


© 2004 DANGER PRESS LLC
`

Is there a way I can apply the font Termina to it from my Templates font manager

And adjust the size to match the text on the right side of the footer, without wrapping the LLC?

Thanks,

J

Hi,

Sorry, I was looking on a different Footer.

I went ahead and made the changes, these are what I have changed.

1 Added a class to your content area element in Customize

2 Add code below in Footer JS

jQuery(function($) {
    var $Year = new Date().getFullYear()
    $('.x-colophon .copyright').html("<span>&copy; 2004 - "+$Year+" DANGER PRESS LLC</span>");
});

3 Added Code below in Footer CSS

.copyright {  
   font-family:'Termina';
}

4 Assign it to test page, to see if it is working.

https://www.staging3.dangerpress.com/test/

Kindly check in your end.

Thanks

2 Likes

Thanks for your help Paul.

I added font-size: 10px; to get it to the correct size and now it looks great.

J

Glad to hear it’s sorted.

Cheers!

This one also works for me. thanks

You’re welcome! :slight_smile: