admin管理员组文章数量:1125739
When my WordPress site loads up, towards the top, I have something that is generated in the DOM....
<a class="skip-link screen-reader-text" href="#content">Skip to content</a>
From my child theme, what action or filter can I use to change the href value from #content
to something like #content-top
? Having trouble to finding resources online that talk about making this adjustment...
I tried the following just to see if it goes away as a test...
remove_action( 'wp_footer', 'the_block_template_skip_link' );
But that has no impact.
When my WordPress site loads up, towards the top, I have something that is generated in the DOM....
<a class="skip-link screen-reader-text" href="#content">Skip to content</a>
From my child theme, what action or filter can I use to change the href value from #content
to something like #content-top
? Having trouble to finding resources online that talk about making this adjustment...
I tried the following just to see if it goes away as a test...
remove_action( 'wp_footer', 'the_block_template_skip_link' );
But that has no impact.
Share Improve this question edited Feb 6, 2024 at 2:55 klewis asked Feb 6, 2024 at 2:49 klewisklewis 8991 gold badge14 silver badges29 bronze badges2 Answers
Reset to default 2If remove_action( 'wp_footer', 'the_block_template_skip_link' )
did not work, then try with remove_action( 'wp_enqueue_scripts', 'wp_enqueue_block_template_skip_link' );
, or both of that. (see source on GitHub)
As for changing the href
value, I'm not aware of any (filter) hook to do that, but you can either edit your template and set the <main>
's id
value to content-top
, or you can use JavaScript to modify the href
value. E.g.
document.querySelector( 'a.skip-link[href="#content"]' ).href = '#content-top';
the_block_template_skip_link
function is a part of the WordPress block editor and is responsible for generating the Skip to content
link in the HTML output. To modify the href value of this link, you can use the the_block_template_skip_link
filter.
For more detail visit :- the_block_template_skip_link()
Add code to your child theme's functions.php
file
function modify_block_template_skip_link($output) {
// Replace the href value with your desired value, e.g., #content-top
$output = str_replace('href="#content"', 'href="#content-top"', $output);
return $output;
}
add_filter('the_block_template_skip_link', 'modify_block_template_skip_link');
本文标签:
版权声明:本文标题:filters - How to change content hash value, within the_block_template_skip_link action? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736662396a1946480.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论