Jump to content

Customising the text on "View event" and "Back to All Events" links

Recommended Posts

You can add the following JS below.

Features:

  • Update the value of the eventButtonText['default'] variable to update all buttons.
  • Target individual buttons using the eventButtonText[<POSITION>] syntax. If you want to customize the button of the 2nd event item, you'd use, eventButtonText[2]. The example below has items 1 and 3 commented out based on the 2 forward slashes in front of the variable. Remove those slashes to uncomment.  
  • Update the value the back to events link by updating the value of the eventBackButtonText variable

JavaScript

(function (document) {

  var eventButtonText = {}; // DO NOT DELETE

  // Back button text.
  var eventBackButtonText = 'Go back to my awsome events!'

  // Default text for all buttons for each event listing item.
  eventButtonText['default'] = 'View my awesome event!';

  // Target specific item in the event listing. Remove the 2 forward slashes
  // below before the `eventButtonText` variableto uncomment the lines. Update
  // the number in the bracket to equal the position of the event in the listing.
  // eventButtonText[1] = 'Event 1';
  // eventButtonText[3] = 'Event 3';

  /**************************************************************************
   * DO NOT EDIT CODE BELOW, unless you know what your doing.
   ***************************************************************************/

  // Initialized code depending on if the user places it in the header or footer
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', init);
  } else {
    init();
  }

  function init() {
    addNodeListForEachPolyfill();

    var eventButtons = document.querySelectorAll('.eventlist .eventlist-button');
    var backLink = document.querySelector('.eventitem-backlink');
    var text;

    if (eventButtons) {
      eventButtons.forEach(function (button, index) {
        index = index + 1;
        text = eventButtonText[index] || eventButtonText['default'];
        if (text) {
          button.textContent = text;
        }
      });
    }

    if (backLink) {
      backLink.textContent = eventBackButtonText;
    }

  }

  function addNodeListForEachPolyfill() {
    if (window.NodeList && !NodeList.prototype.forEach) {
      NodeList.prototype.forEach = Array.prototype.forEach;
    }
  }

})(document);

Be sure to place the code above between <script> tags, example:

<script>
  // Add js code here
</script>

 

Full stack developer who loves helping people out with anything web related. If you'd like to support me, buy me a coffee!

Link to comment
  • 2 months later...
5 hours ago, HaileeWestberry said:

I am trying to do the same thing and I can't get the code to update my buttons and back link. Miguel, did you place this in the page header code injection section or add the code in the footer? Would you mind taking a screen shot of how you accomplished this? I'm new to JS coding, so I would be very appreciative! 

Yesterday I solve a same question, if you search on forum, I think you can find it out.

Or can you share link to event? We can check easier.

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
  • 2 weeks later...
  • 2 weeks later...

Hey all - 

I'm on a similar, but different quest. I am trying to redirect the "Back to all events" link to a different page itself. I have used the script below, but I'm missing something - I can't get it to work.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script> 
   $(document).ready(function() { 
     $('.eventitem-backlink[href="/events-workshops?view=calendar&amp;month=07-2020"]').attr("href", "/workshops");
   }); 
</script>

Web page: https://fairfaxbackyardfarmer.squarespace.com/events-workshops/template-workshop

 

 

I would appreciate any direction or ideas! Thank you!

Edited by MayaViolet
Link to comment

You can try something like the following.

$( '.eventitem-backlink' ).attr ( 'href', '/workshops' );

This is for a v7 site using a Brine family template.

That targets the class of the link.

Let us know how it goes.

Edited by creedon
clarified SS version and template family

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
  • 1 month later...
  • 4 months later...

@AziJamalian

Please post the URL for a page with the view event "button" on your site.

If your site is not public please set up a site-wide password, if you've not already done so.

Post the password here.

Adding a site-wide password is not a security breach. Please read the documentation at the link provided to understand how it works.

We can then take a look at your issue.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
  • 5 weeks later...
21 minutes ago, Zkoster said:

@creedon @jpeter

Hi guys! This helps a lot. Where can I edit this code? I tried to do it within events code block but it didn't work out.

Settings > Advanced > code Injection > Footer or Header

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
  • 4 months later...

@margmorg

Add the following to Blog Settings > Advanced > Page Header Code Injection for the blog page.

<style>

  /* hide back to all events link */
  
  .eventitem-backlink {
  
    display : none;
    
    }
    
  </style>

This is for v7.1.

Let us know how it goes.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
  • 9 months later...
2 hours ago, Nikitaly said:

but this is not working for me.

The first issue to solve is that the code has been installed improperly. There is code missing and so it is erroring out. Please reinstall making sure to add all the provided.

114676165_ScreenShot2022-07-20at11_17_31AM.thumb.png.5ca6942db3082a763a7e065318a0f771.png

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
22 hours ago, Nikitaly said:

It should be correct now.

Same error as before. Code has not changed from last I looked.

1872973650_ScreenShot2022-07-20at3_58_09PM.png.dbbc29e0ae2bc555dba59c6847ea6a4c.png

Edited by creedon

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

Create an account or sign in to comment

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

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.