GoToTop link

Community Forums Forums General Discussion GoToTop link

This topic is: resolved

This topic contains 6 replies, has 2 voices, and was last updated by  marjwyatt 1 year ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #34059

    marjwyatt
    Participant
    Post count: 26

    I’ve finally noticed that the GoToTop link in the Genesis framework leads to http://yourdomainname.com/#wrap, where the site url varies with the actual domain name.  With headers of lesser height, this returns the link clicker to a point where part of the header is obfuscated by the wpadmin bar (if logged in).

    I’m not a fan of really tall header spaces because, in my humble opinion, they consume too much of the vertical height of the page and I build a lot of membership sites for my clients so this is becoming a bother.

    This is the code that is adding #wrap to the href link, found in the genesis shortcodes folder:
    <code>

    add_shortcode( ‘footer_backtotop’, ‘genesis_footer_backtotop_shortcode’ );
    /**
    * Produces the “Return to Top” link.
    *
    * Supported shortcode attributes are:
    * after (output after link, default is empty string),
    * before (output before link, default is empty string),
    * href (link url, default is fragment identifier ‘#wrap’),
    * nofollow (boolean for whether to make the link include the rel=”nofollow”
    * attribute. Default is true),
    * text (Link text, default is ‘Return to top of page’).
    *
    * Output passes through ‘genesis_footer_backtotop_shortcode’ filter before returning.
    *
    * @since 1.1.0
    *
    * @param array $atts Shortcode attributes
    * @return string Shortcode output
    */
    function genesis_footer_backtotop_shortcode( $atts ) {
    $defaults = array(
    ‘after’ => ”,
    ‘before’ => ”,
    ‘href’ => ‘#wrap’,
    ‘nofollow’ => true,
    ‘text’ => __( ‘Return to top of page’, ‘genesis’ ),
    );
    $atts = shortcode_atts( $defaults, $atts );
    $nofollow = $atts['nofollow'] ? ‘rel=”nofollow”‘ : ”;
    $output = sprintf( ‘%s<a href=”%s” %s>%s</a>%s’, $atts['before'], esc_url( $atts['href'] ), $nofollow, $atts['text'], $atts['after'] );
    return apply_filters( ‘genesis_footer_backtotop_shortcode’, $output, $atts );
    }</code>

    I see it is a default for that output.  What is the best method for filtering that link to make it be href # instead of href #wrap?


    Virtually Marj Wyatt
    VirtuallyMarj.com | Twitter | Facebook | Google +

    #34282

    surefirewebserv
    Participant
    Post count: 67

    No need to change that, that’s the actual code that creates the short code, but the short code already has the href attribute in place: [footer_backtotop text="Top" href="#content"]

    You can change it to anything you want.

    Here’s the filter to change what the default is:

    add_filter( 'genesis_footer_backtotop_text', 'custom_footer_backtotop_text' );
    function custom_footer_backtotop_text($backtotop) {
    	$backtotop = '[footer_backtotop text="Return to Top" href="#content"]';
    	return $backtotop;
    }

    That should work.


    SureFireWebServices.com | Genesis Tuts and More
    Genesis Theme Starter Kit | It’s Free

    #34294

    marjwyatt
    Participant
    Post count: 26

    Thanks for the suggestion but it didn’t work for me.  In fact, that code makes the link to the top not work at all.


    Virtually Marj Wyatt
    VirtuallyMarj.com | Twitter | Facebook | Google +

    #34301

    surefirewebserv
    Participant
    Post count: 67

    That code works, just tested it. Did you put it in the functions.php file? Did you change #content to where you want the back to top to go? Are you using a child theme?

    You can copy this verbatim

    add_filter( 'genesis_footer_backtotop_text', 'custom_footer_backtotop_text' );
    function custom_footer_backtotop_text($backtotop) {
        $backtotop = '[footer_backtotop text="Return to Top" href="#"]';
        return $backtotop;
    }

    An alternate solution would be to download the genesis simple edits plugin and edit the footer info using the back to top shortcode with href=”#”

    [footer_backtotop text="Top" href="#"]

    More information on the shortcodes are found here: http://my.studiopress.com/docs/shortcode-reference/#footer-backtotop-shortcode


    SureFireWebServices.com | Genesis Tuts and More
    Genesis Theme Starter Kit | It’s Free

    #34308

    marjwyatt
    Participant
    Post count: 26

    An alternate solution would be to download the genesis simple edits plugin and edit the footer info using the back to top shortcode with href=”#”

     

    I’m really not a big fan of adding plugins to any site for such a simple issue.  The second idea you suggest did work.  I had tried that next and just hadn’t gotten back her to update the thread as being resolved.

    Where do I post a suggestion that this shortcode be changed in the framework itself.  It seems “wrong” to have it go to #wrap in the first place, to me.


    Virtually Marj Wyatt
    VirtuallyMarj.com | Twitter | Facebook | Google +

    #34320

    surefirewebserv
    Participant
    Post count: 67

    Well I wouldn’t necessarily say that it’s wrong, #wrap is the first tag on the top of the site, it only seems like the issue you’re seeing is when someone is logged in and the admin bar is being displayed. There are ways around that, simply turning the admin bar off on the front end would fix it.

    In any case, the short code and filter I provided allows you to change it to go wherever you want, so the flexibility to change it is there, and that’s what really matters.

    It’s just a matter of preference.


    SureFireWebServices.com | Genesis Tuts and More
    Genesis Theme Starter Kit | It’s Free

    #34329

    marjwyatt
    Participant
    Post count: 26

    @surefirewebserv … thanks again for your suggestions.  The one that finally worked was discovered by me prior to your suggestion, however.  I just hadn’t found the Genesis tutorial that indicated we could change the href destination within the code that alters the backtotop text.

    As for the workaround of turning off the admin bar, of course I’m aware of that.  I did mention that I am building a lot of membership sites, right?  For those memberships, I am authoring code that gives the members perpetual access to the links they need on the site, like the members home portal, etc.  To that end, turning off the admin bar is counterproductive.

    To my way of thinking, the top of the page is the top of the page, not the top of the wrap for that page.  So, we will have to agree to disagree on whether or not # is preferred over #wrap.  In my opinion, it is not. and I will alter this filter on every custom theme that I write going forward, until the Genesis Framework makes a change.


    Virtually Marj Wyatt
    VirtuallyMarj.com | Twitter | Facebook | Google +

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.