• Resolved spiralwriter

    (@spiralwriter)


    Hello there,

    I use one of the buy buttons to sell books directly from my site. That link opens a page with different buying options. It would be fantastic if I could get that one button only to not open in a new tab. With each click doing that, if someone buys 5 books, they end up with 5 open tabs.

    I can see in the code where the button array uses target=”_blank” to make that happen. What I can’t figure out is how to make that change for only one button rather than all three. Is that possible?

    Thank you!
    Kari

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi Kari

    If you plan to modify the plugin, you could change the genesis_author_pro_get_buttons function to look like this:

    function genesis_author_pro_get_buttons( $post_id = '' ) {
    
    	$buttons = array( 'button_1', 'button_2', 'button_3' );
    	$values  = array();
    
    	foreach( $buttons as $button ){
    
    		$uri    = genesis_author_pro_get_book_meta( $button . '_uri' , $post_id );
    		$text   = genesis_author_pro_get_book_meta( $button . '_text', $post_id );
    		$target = ( $button === 'button_3' ) ? '' : 'target="_blank" rel="noopener noreferrer"';
    
    		if ( empty( $uri ) || empty( $text ) ) {
    			continue;
    		}
    
    		$values[] = sprintf( '<a href="%1$s" class="button button-book" %2$s>%3$s</a>', $uri, $target, $text );
    
    	}
    
    	return empty( $values ) ? false : implode( '', $values );
    
    }

    Note that this change will be overwritten during plugin updates, though.

    You could alternatively add a script to remove the target attribute on the third button at Appearance → Customize → Theme Settings → Header/Footer Scripts → Footer Scripts:

    <script>
    var thirdButton = document.querySelectorAll(".single-books .book-details .button-book:nth-of-type(3)");
    if (thirdButton.length > 0) {
    	thirdButton[0].removeAttribute("target");
    }
    </script>

    This won’t work if JavaScript is disabled, but it also won’t be removed after plugin updates.

    I hope that helps as a starting point. If you need further help with this or other StudioPress theme and plugin customisations, I recommend the community resources here: https://my.studiopress.com/community/.

    Thread Starter spiralwriter

    (@spiralwriter)

    Hi Nick,

    Thank you for the quick response!

    I would prefer the first version, especially since the plugin isn’t updated terribly often. ?? Unfortunately when I modified the file, I ended up with a parse error on the site. Just in case I have a strange version, I’ll copy the original text from my site below.

    Have a great weekend!
    Kari

    function genesis_author_pro_get_buttons( $post_id = ” ) {

    $buttons = array( ‘button_1’, ‘button_2’, ‘button_3’ );
    $values = array();

    foreach( $buttons as $button ){

    $uri = genesis_author_pro_get_book_meta( $button . ‘_uri’ , $post_id );
    $text = genesis_author_pro_get_book_meta( $button . ‘_text’, $post_id );

    if( empty( $uri ) || empty( $text ) ){
    continue;
    }

    $values[] = sprintf( ‘%s‘, $uri, $text );

    }

    return empty( $values ) ? false : implode( ”, $values );

    }

    Thread Starter spiralwriter

    (@spiralwriter)

    Hi again!

    Never mind, I caught the problem. That worked like a charm the second time.

    Thank you SO much!
    Kari

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Need third buy button to open on same page’ is closed to new replies.