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
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

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.