Skip Links


First I want to thank Maurice Tadros for taking over development of this great Framework!

I am using a GDPR Cookie plugin that uses the separation between head and body using the corresponding tags to do it's work. Because the beans skip links are there between the closing head tag and the opening body tag, it's not working.

I am trying to move the skip links right after the opening body tag, but am having trouble doing so. I can change it in the beans header.php file, but I am trying to do this the right way in my child theme and I can't do so. I can remove the markup using the following code:

beans_remove_markup( 'beans_skiplinks' );
beans_remove_markup( 'beans_skip_links_list' );
beans_remove_markup( 'beans_skip_links_item' );
beans_remove_markup( 'beans_skip_links_item_link' );
add_filter( 'beans_skip_links_list', '__return_false' );

but I can't seem to add it back in. I tried:

add_action( 'beans_site_before_markup', __NAMESPACE__ . '\add_skip_links_after_opening_body_tag', 10, 1);
function add_skip_links_after_opening_body_tag() {
    beans_build_skip_links();
}

I'm not exactly sure what I'm doing wrong. I tried a few variations on that function but nothing is working.

Any help would be much appreciated! Laura


Hi Laura, sorry for the delay I did not see the message.

It has been a pleasure adding to Beans as it is an amazing framework. Can you send the link to the plugin you used and I'll try to replicate it locally.

Cheers, Maurice


Hi Maurice,

The plugin I am using is GDPR Cookie Consent. I am using the premium version but I don't think that would make a difference.

My question really doesn't have anything to do with the plugin though, it's just the reason I would like to do what I am asking, which is to move the skip links from in between the closing head tag and the opening body tag to right after the opening body tag.

At the momen I just removed them using the code referenced in my initial post. So, now I just need to know how I can add them back in after the opening body tag.

Thanks! Laura


Hello,

I took a closer look at the function beans_build_skip_links(), and you are correct there is no easy way that I could see to accomplish what you requested. I wrote a little hack to get around that, till header.php is updated to support this.

Hope this helps, Maurice

add_action('init', __NAMESPACE__ .'\cache_beans_skiplinks');
/**
 * Caches the output from the function beans_build_skip_links(), then removes the default markup.
 *
 * In the file lib/templates/structure/header.php - the function beans_build_skip_links() is directly called,
 * without the typical beans support.
 *  To get around this - we capture the output buffer and store it Wordpress's cache.
 * Then remove all the markup from the function beans_build_skip_links
 * The markup can be retrieved and inserted in any hook we want after that.
 *
 * @return null
 */
function cache_beans_skiplinks(){

    ob_start();
    beans_build_skip_links();
    $links = ob_get_contents();
    ob_end_clean(); 

    wp_cache_set('_beans_skiplinks_html', $links);

    beans_remove_markup( 'beans_skiplinks' );
    beans_remove_markup( 'beans_skip_links_list' );
    beans_remove_markup( 'beans_skip_links_item' );
    beans_remove_markup( 'beans_skip_links_item_link' );
    add_filter( 'beans_skip_links_list', '__return_false' );
}

add_action( 'beans_site_before_markup',  __NAMESPACE__ .'\add_skip_links_after_opening_body_tag', 10, 1);
/**
 * echo the original html from beans_build_skip_links()
 */
function add_skip_links_after_opening_body_tag() {
    echo wp_cache_get('_beans_skiplinks_html');
}

Hi Maurice,

Great, I will try it out.

Do you know why the skip links were added between the tags instead of after the opening body tag in the first place?

Thanks again! Laura


Hopefully that works for you. I'm sure Thierry or Tonya had there reasons but it was before my time here so I'm not really sure.

Cheers


That worked beautifully. Thank you!

Write a reply

Login or register to write a reply, it's free!