Jump to content

Auto Changing Content in Text Block Every Visit

Recommended Posts

Site URL: https://opossum-apricot-tzsp.squarespace.com/

I'm trying to create a text block that will generate a different sentence every time the home page is visited/refreshed. I'm very new to coding and I'm not sure where to start. Is there some custom css I can use to accomplish this? I have tried creating a blog post and then a summary carousel with just the headers, but the formatting of the text doesn't match with the H1 of the rest of the site. I've considered just creating PNG files of all the text and then trying the carousel again, but I'm afraid the formatting would look strange on mobile with the image sizing. Any help would be greatly appreciated. 

Link to comment
  • Replies 1
  • Views 1.1k
  • Created
  • Last Reply

Use this code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
 var textToShow = ['text1', 'text2', 'text3', 'text4']
    $(document).ready(function() {
        $("h4").html(textToShow[Math.floor(Math.random()*textToShow.length)]);
    });
</script>

replace h4 with text block class

replace text1, text2,...

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

Archived

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

×
×
  • 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.