Jump to content

Display different announcement bar message on only one page

Recommended Posts

  • Replies 3
  • Views 536
  • Created
  • Last Reply
On 3/18/2021 at 4:46 PM, Andyjk said:

Site URL: https://www.andykerrphotography.com

Does anyone know how to display a different announcement bar message on a single page, so that it's a different message than the one at the top of all other pages please?

Many thanks in advance.

Hi. You mean Plan your...text? or both Plan... + learn more link?

Also do you use Business or Commerce Plan?

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

Add the following to Page Settings > Advanced > Page Header Code Injection for the page where you want to have a different announcement bar.

<!--

  begin change announcement bar for page
  
  SS Version : 7.0
  Template   : Brine template family
  
  -->
  
  <style>
  
    body:not( .sqs-edit-mode ) .Main-content .sqs-block-horizontalrule:nth-last-of-type( 2 ),
    body:not( .sqs-edit-mode ) .Main-content .sqs-block-html:nth-last-of-type( 1 )
    
      {
      
        display : none;
        
        }
        
    </style>
    
  <script>
  
    $( ( ) => {
    
      const url = 'https://www.squarespace.com/';
      
      // do not change anything below, there be the borg here
      
      if ( window.frameElement !== null ) return;
      
      if ( ! ( 'MutationObserver' in window ) ) return;
      
      const forceObserverDisconnect = setTimeout ( ( ) => {
      
        // disconnect when bar doesn't show up if user has closed it
        
        observer.disconnect ( );
        
        }, 1000 * 15 );
        
      let barUrl = ( $e ) => {
      
        if ( ! url ) return;
        
        let $barUrl = $( '.sqs-announcement-bar-url', $e );
        
        if ( $barUrl.length ) {
        
          $barUrl.attr ( 'href', url );
          
          } else {
          
            $( '<a>' )
            
              .addClass ( 'sqs-announcement-bar-url' )
              
              .attr ( 'href', url )
              
              .attr ( 'aria-labelledby', 'announcement-bar-text-inner-id' )
              
              .prependTo ( '.sqs-announcement-bar-content', $e );
              
            }
        }
        
      const observer = new MutationObserver ( function ( mutations ) {
      
        $.each ( mutations, function ( ) {
        
          if ( ! this.addedNodes.length ) return;
          
          let $e = $( this.addedNodes [ 0 ] );
          
          if ( ! $e.hasClass ( 'sqs-announcement-bar-custom-location' ) )
          
            return;
            
          let $content = $( '.Main-content .sqs-block-html:last ' +
          
            '.sqs-block-content p' );
            
          $( '#announcement-bar-text-inner-id p' ).replaceWith ( $content );
          
          barUrl ( $e );
          
          clearTimeout ( forceObserverDisconnect );
          
          observer.disconnect ( );
          
          } );
          
        } );
        
      // starts listening for changes in announcement bar drop zone
      
      observer.observe ( $( '.sqs-announcement-bar-dropzone' ) [ 0 ], {
      
        childList : true
        
        } );
        
      } );
      
    </script>
    
  <!-- end change announcement bar for page -->

At the bottom of the page add a line block and a text block.

1555225238_ScreenShot2021-03-22at2_21_47PM.png.759c71290be251991e7652d8e9549076.png

This is for v7.0 using Brine template family.

You won't see the effect while you are in Preview.  To see it use private browsing. Also note that the effect won't show if the user has closed their announcement bar.

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

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.