Elementor 开发者文档

title: "Skip Link URL" post_status: publish comment_status: open taxonomy: category: - elementor-developers-docs post_tag: - Hello Elementor Theme - Src - Repos


Skip Link URL

The theme has a "Skip to content" link at the top of the page, it's used by screen readers to quickly navigate to the main content area. Developers can modify the skip link URL using a filter hook in a child-theme.

Hook Details

The hook controls the URL of the main content on the page. By default it links to #content, i.e. an element with a content ID.

Usage

To modify the skip link URL, use the following hook in a child-theme functions.php file:

function custom_hello_elementor_skip_link_url() {
    return '#main';
}
add_filter( 'hello_elementor_skip_link_url', 'custom_hello_elementor_skip_link_url' );

For conditional URLs based on WordPress Template Hierarchy use the following hook:

function custom_hello_elementor_skip_link_url() {
    if ( is_404() ) {
        return '#404-content';
    } else if ( is_page() ) {
        return '#page-content';
    } else if ( is_post() ) {
        return '#post-content';
    } else {
        return '#main-content';
    } 
}
add_filter( 'hello_elementor_skip_link_url', 'custom_hello_elementor_skip_link_url' );