Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't prevent addition of skip-link using PHP #40118

Closed
ClarusDignus opened this issue Apr 6, 2022 · 2 comments
Closed

Can't prevent addition of skip-link using PHP #40118

ClarusDignus opened this issue Apr 6, 2022 · 2 comments
Labels
Needs Technical Feedback Needs testing from a developer perspective.

Comments

@ClarusDignus
Copy link

ClarusDignus commented Apr 6, 2022

Description

I'm creating a block theme from scratch using FSE.

I'm trying to understand how the skip-link is added: #30336 (comment).

I want to stop the skip-link's script and style being added to each page.

I've tried the following in functions.php:

// Attempt 1
remove_action( 'wp_body_open', 'gutenberg_the_skip_link' );

//Attempt 2
remove_action( 'init', 'gutenberg_the_skip_link' );

// Attempt 3
remove_action( 'wp_body_open', 'the_block_template_skip_link' );

// Attempt 4
remove_action( 'init', 'the_block_template_skip_link' );

I’m not removing the skip-link; I’m replacing it because I need to wrap it in a div and change the link text to title case:

add_action( 'wp_body_open', 'custom_skip_link' );

function custom_skip_link() {
    echo '
    <div class="custom-skip-link-container">
        <a class="custom-skip-link" href="#content">Skip to Content</a>
    </div>
    ';
}

I can remove the skip-link using jQuery but I’d prefer to stop it being added in the first place using PHP.

(function($) {
    $(document).ready(function() {
        $("a.skip-link, style#skip-link-styles").remove();
    })
})(jQuery);

Step-by-step reproduction instructions

  1. Open functions.php.
  2. Try to prevent addition of skip-link by removing one of the following actions: gutenberg_the_skip_link() or the_block_template_skip_link().

Screenshots, screen recording, code snippet

Environment info

  • WordPress 5.9.2 using custom block theme created using FSE
  • Gutenberg 12.9.0

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

No

@Mamaduka Mamaduka added the Needs Technical Feedback Needs testing from a developer perspective. label Apr 7, 2022
@Gierand
Copy link

Gierand commented Apr 7, 2022

@ClarusDignus try this:
remove_action( 'wp_footer', 'the_block_template_skip_link' );

@ClarusDignus
Copy link
Author

@ClarusDignus try this: remove_action( 'wp_footer', 'the_block_template_skip_link' );

That worked. Thanks. My bad. I didn't consider wp_footer(). I incorrectly assumed the_block_template_skip_link() was being applied to wp_body_open() because of the skip-link's position in the page.

I can see now that the skip-link's position is determined in relation to the site wrapper using JavaScript:

// Get the site wrapper.
// The skip-link will be injected in the beginning of it.
sibling = document.querySelector( '.wp-site-blocks' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Technical Feedback Needs testing from a developer perspective.
Projects
None yet
Development

No branches or pull requests

3 participants