Jump to content

Website Logo link for Members

Recommended Posts

  • Replies 12
  • Views 588
  • Created
  • Last Reply

 Add the following to Settings > Advanced > Code Injection > FOOTER.

Do not use the following code. Find the other, better version of the code elsewhere in this thread.

<script>

  $( ( ) => {
  
    // when member is logged in change url of logo
    
    const url = '/home-1';
    
    // do not change anything below, there be the borg here
    
    if ( ! $( '.user-accounts-link .auth' ).length ) return;
    
      $( '.header-title a' ).attr ( 'href', url );
      
    } );
    
  </script>

This is for a v7.1 site.

For others following along Karkon already has jQuery installed. If you don't then add the following to Settings > Advanced > Code Injection > HEADER. 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

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

Hi @creedon thanks so much for your advise. I copied the below code in the footer.

Quote

<script>

  $( ( ) => {
  
    // when member is logged in change url of logo
    
    const url = '/home-1';
    
    // do not change anything below, there be the borg here
    
    if ( ! $( '.user-accounts-link .auth' ).length ) return;
    
      $( '.header-title a' ).attr ( 'href', url );
      
    } );
    
  </script>

 

it does re-direct the logo to the members home page /home-1  but it looks like it also works when members aren't logged in. I just tried while logged out and it takes me to the access denied page all the time.

Any other suggestion?

 

thanks

Link to comment
14 hours ago, Karkom said:

Any other suggestion?

It appears the issue is a bit deeper than my initial testing indicated. 😞

I suggest backing out the code I posted and let me cogitate on the issue. The code being in place was invaluable to further testing how member authentication is functioning as far as the elements on the page go.

Just a quick note for those into the deeper stuff. When the page is first loaded both the auth and noauth class elements are loaded. Then some code comes along and removes the unneeded element depending on if the member is logged in or not.

The jQuery ready document code I wrote runs before the member is/is not logged in code runs. So it always finds the auth class. Of course when I was developing the code I was either logged in or not logged in and the code I ran in the console happened way after jQuery's document ready and the member logged in or not code ran.

I'm thinking Mutation Observer! One of my favorite friends for those ephemeral elements! 🙂 LOL!

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

Add the following to Settings > Advanced > Code Injection > FOOTER.

<script>

  $( ( ) => {
  
    /*
    
      change url of logo when member is logged in to site
      
      SS Version : 7.1
      
      */
      
    const url = '/home-1';
    
    // do not change anything below, there be the borg here
    
    if ( ! ( 'MutationObserver' in window ) ) return;
    
    const observer = new MutationObserver ( function ( mutations ) {
    
      mutations.forEach ( function ( mutation ) {
      
        if ( ! mutation.removedNodes.length ) return;
        
        observer.disconnect ( );
        
        let $e = $( mutation.removedNodes [ 0 ] );
        
        if ( $e.hasClass ( 'auth' ) ) return;
        
        $( '.header-title a' ).attr ( 'href', url );
        
        } );
        
      } );
      
    // start listening for changes in element with class user-accounts-text-link
    
    observer.observe ( $( '.user-accounts-text-link' ) [ 0 ], {
    
      childList: true
      
      } );
      
    } );
    
  </script>

Normally I would have updated my original code post but in this case I think there is an instructive element to the process.

I've done the best I can in testing as on my test site I don't have full access to member areas functionality. SS please consider allowing full access to member areas on non-published sites, like many of your other features that are considered premium. Help the developers to help you. Not that I expect SS to read this but if you do, there you go.

As long as the new code is not causing any problems, please leave it in place so I can examine it, if it doesn't work.

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.