Translating 2nd button on slider


#1

Hi,

I was able to create a second button on the Sydney slider using some JQuery code I found here:

jQuery(function($) {
var myButton = ‘My Button’;
$( ‘.slide-inner’ ).append(myButton);
});

It works great.

My question is: I run a multilingual site. It works on my Dutch front page. How can I create or translate my second button for my English front page (target URL and button text)?

Thank you in advance!

Kind regards, Alice


#2

Dear Alice,

Try this code, please:


;(function($) {

   'use strict'

   if( $('.button-slider').length ){

     var currentLang = $('html').attr('lang');
     var btnURL      = '';
     var btnText     = '';

     if(currentLang == 'nl_NL'){ /* For Dutch */
       btnURL   = 'http://yoursite.com/url-for-dutch'; 
       btnText  = 'Button for Dutch';
     }

     if(currentLang == 'en_US'){ /* For English US */
       btnURL   = 'http://yoursite.com/url-for-english'; 
       btnText  = 'Button for English';
     }    

     var myButton = '<a href="'+btnURL+'">'+btnText+'</a>';
     
     $( '.slide-inner' ).append(myButton);

     
   }
   

})(jQuery);

Regards,
Kharis


#3

Hi Kharis,

Thank you for your answer. Unfortunately it doesn’t seem to work. No second button shows up on any of the pages. Do you have something else I can try?

Thank you in advance.

Kind regards, Alice


#4

Hi Kharis,

There where two = signs in two places, I deleted one. Now it works, but not completely. The text for the English button shows up on both pages and it is a link, not a button. Any ideas?

Thank you in advance.

Kind regards, Alice


#5

Dear Alice,

Could you please share the link to your site, so I can inspect it and be more exact?

Regards,
Kharis


#6

Hi Kharis,

My website is still in development and really not ready yet. I took the maintanance of for today. My website: www.valuex.nl

Thank you.

Kind regards, Alice


#7

Dear Alice,

Thank you for the followup.

So sorry, I suggested incorrect code. Please try this one:


;(function($) {

   'use strict'

   if( $('.button-slider').length ){

     var currentLang = $('html').attr('lang');
     var btnURL      = '';
     var btnText     = '';

     if(currentLang == 'nl-NL'){ /* For Dutch */
       btnURL   = 'http://yoursite.com/url-for-dutch'; 
       btnText  = 'Button for Dutch';
     }

     if(currentLang == 'en-US'){ /* For English US */
       btnURL   = 'http://yoursite.com/url-for-english'; 
       btnText  = 'Button for English';
     }    

     var myButton = '<a href="'+btnURL+'">'+btnText+'</a>';
     
     $( '.slide-inner' ).append(myButton);

     
   }
   

})(jQuery);

You would clear your web browser’s cache before reloading your site to see the code change takes affect.

Let me know how it goes. I’ll wait to hear back from you regarding your stats.

Regards,
Kharis


#8

Hi Kharis,

It now has the right button text and link for every page, but is it still a link, not a button. Any suggestons?

Thank you in advance.

Kind regards, Alice


#9

Dear Alice,

Sorry for the misled.

Please replace this line:


var myButton = '<a href="'+btnURL+'">'+btnText+'</a>';

with:


var myButton = '<a href="'+btnURL+'" class="roll-button button-slider">'+btnText+'</a>';

Regards,
Kharis


#10

Perfect! Thank you Kharis for all your help! It looks great! And I learned a little bit about jQuery.

Kind regards, Alice


#11

That sounds great!

I am glad it is working for you at this time!

I am marking this thread as resolved. Please let us know in a new topic if you have any further questions, or if we can provide you with any other assistance.

If you don’t mind, could you please rate our Sydney theme here? We would highly appreciate it if you do so.

Regards,
Kharis


#12

I will do that.