Jump to content

MattTheDesigner

Member
  • Posts

    2
  • Joined

  • Last visited

Posts posted by MattTheDesigner

  1. On 4/5/2021 at 6:38 PM, creedon said:

    This solution requires the business plan or above.

    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>

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

    <script>
    
      $( ( ) => {
      
        /*
        
          change blog listing item image URL to Source URL
          
          SS Version : 7.0
          
          Templates  : Brine ( Aria, Blend, Cacao, Clay, Fairfield, Feed, Foster,
                       Greenwich, Hatch, Heights, Hunter, Hyde, Impact, Jaunt, Juke,
                       Keene, Kin, Lincoln, Maple, Margot, Marta, Mentor, Mercer,
                       Miller, Mojave, Moksha, Motto, Nueva, Pedro, Pursuit, Rally,
                       Rover, Royce, Sofia, Sonora, Stella, Thorne, Vow, Wav, West )
                       
          */
          
        let targetAtttributeValue = ''; /* use _self | _blank | _parent | _top |
                                           framename see
                                           < https://mzl.la/2Q0JROF > */
        
        // do not change anything below, there be the borg here
        
        if ( ! $( '.BlogList' ).length ) return; // bail if not blog listing page
        
        $( '.BlogList-item-title' )
        
          .filter ( function ( ) {
          
            return $( this ).attr ( 'target' ) !== undefined;
            
            } )
            
          .each ( function ( ) {
          
            const $this = $( this );
            
            const url = $this.attr ( 'href' );
            
            let $imageLink = $this
            
              .prev ( '.BlogList-item-image' )
              
              .find ( '.BlogList-item-image-link' )
              
                .attr ( 'href', url );
                
            if ( ! targetAtttributeValue ) {
            
              const v = $this.attr ( 'target' );
              
              if ( v !== undefined ) targetAtttributeValue = v;
              
              }
              
            if ( targetAtttributeValue )
            
              $imageLink.attr ( 'target', targetAtttributeValue );
              
            } );
            
        } );
        
      </script>

    This is for v7.0 using the Brine template family.

    Let us know how it goes.

    This is amazing, thank you. Really helpful. 

    After using your code to change the BlogList-item-image link, I'd love to do the same with the read more button that goes under my article links (BlogList-item-readmore) 

    Any idea how I'd go about that? Could I reuse the above and just change some parts?

    Cheers!

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