[Resolved] Excerpt Read More Arial Label

Home Forums Support [Resolved] Excerpt Read More Arial Label

Home Forums Support Excerpt Read More Arial Label

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2518076
    Rachel

    Hi there,

    I use the following snippet for the excerpt read more text. However I am getting warnings as there is no aria-label associated with the read more link. Is there a way to adjust this snippet to add an aria-label for the read more link text?

    I assume the standard would be to include the title of the post in the aria-label?

    Thanks,
    Rachel

    add_filter( ‘wp_trim_excerpt’, ‘tu_excerpt_metabox_more’ );
    function tu_excerpt_metabox_more( $excerpt ) {
    $output = $excerpt;

    if ( has_excerpt() && ! is_feed() ) {
    $output = sprintf( ‘%1$s %3$s‘,
    $excerpt,
    get_permalink(),
    __( ‘Read more’, ‘generatepress’ )
    );
    }

    return $output;
    }

    #2518127
    Fernando
    Customer Support

    Hi Rachel,

    Can you try this code instead?:

    add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' );
    function tu_excerpt_metabox_more( $excerpt ) {
        $output = $excerpt;	
    
        if ( has_excerpt() ) {
            $output = sprintf( '%1$s <a href="%2$s" aria-label="%4$s">%3$s</a>',
                $excerpt,
                get_permalink(),
                __( 'Read more', 'generatepress' ),
    sprintf(
    	       /* translators: Aria-label describing the read more button */
    	       _x( 'Read more of the post %s', 'more on post title', 'generatepress' ),
    	       the_title_attribute( 'echo=0' )
           )
            );
        }
    
        return $output;
    }
    #2519534
    Rachel

    Hi Fernando
    Great – that has worked, thank you.

    I just modified your code slightly to include my exclusion of the read more text from the RSS feed, as was in the original code.

    Cheers,
    Rachel

    add_filter( ‘wp_trim_excerpt’, ‘tu_excerpt_metabox_more’ );
    function tu_excerpt_metabox_more( $excerpt ) {
    $output = $excerpt;

    if ( has_excerpt() && ! is_feed() ) {
    $output = sprintf( ‘%1$s %3$s‘,
    $excerpt,
    get_permalink(),
    __( ‘Read more’, ‘generatepress’ ),
    sprintf(
    /* translators: Aria-label describing the read more button */
    _x( ‘Read more of the post %s’, ‘more on post title’, ‘generatepress’ ),
    the_title_attribute( ‘echo=0’ )
    )
    );
    }

    return $output;
    }

    #2519552
    Fernando
    Customer Support

    You’re welcome, Rachel!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.