• Resolved Clarus Dignus

    (@clarus-dignus)


    the_block_template_skip_link() in wp-includes/block-template.php inserts the skip link. I want to stop the insertion.

    In functions.php, I’ve tried the following to no avail:

    // Attempt 1
    remove_action( 'wp_body_open', 'gutenberg_the_skip_link' );
    
    // Attempt 2
    remove_action( 'wp_body_open', 'the_block_template_skip_link' );
    
    // Attempt 3
    add_filter( 'the_block_template_skip_link',  '__return_false' );
    
    // Attempt 4
    remove_action( 'init', 'the_block_template_skip_link' );

    I understand why the skip link is important. I’m not deleting it; 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="skip-link-container">
    		<a class="skip-link screen-reader-text" href="#content">Skip to Content</a>
    	</div>
      ';
    }

    I understand I can remove the skip link using jQuery but I’d prefer to stop the insertion using PHP.

    To clarify, I’d also like to stop the insertion of the corresponding CSS.

Viewing 1 replies (of 1 total)
  • Thread Starter Clarus Dignus

    (@clarus-dignus)

    This works:

    remove_action( 'wp_footer', 'the_block_template_skip_link' );

    I didn’t consider removing the action from 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' );
    
    [...]
    
    // Inject the skip link.
    sibling.parentElement.insertBefore( skipLink, sibling );
Viewing 1 replies (of 1 total)

The topic ‘Stop PHP/JavaScript inserting the skip link’ is closed to new replies.