Support » Theme: Astra » Class for read-more links

  • Resolved zabavljaev

    (@zabavljaev)


    Hello! Could you please tell me why the link class in “read-more” is empty? And how to assign a class for links?
    <p class="read-more"> <a class="" href="http://s91573pd.bget.ru/?p=299"> <span class="screen-reader-text">Winter Birding</span> Читать полностью »</a></p>

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • I could do it with jQuery, but I would like with functions.php.
    jQuery("p.read-more a").addClass("myclass");
    This is optional for me, as I can use the CSS construct .read-more a {…}. However, I would like to know why the link class is empty.

    I took as a basis the function of the theme Astra:

    /**
     * Function to get Read More Link of Post
     *
     * @since 1.0.0
     * @return html
     */
    if ( ! function_exists( 'astra_post_link' ) ) {
    
    	/**
    	 * Function to get Read More Link of Post
    	 *
    	 * @param  string $output_filter Filter string.
    	 * @return html                Markup.
    	 */
    	function astra_post_link( $output_filter = '' ) {
    
    		$enabled = apply_filters( 'astra_post_link_enabled', '__return_true' );
    		if ( ( is_admin() && ! wp_doing_ajax() ) || ! $enabled ) {
    			return $output_filter;
    		}
    
    		$read_more_text    = apply_filters( 'astra_post_read_more', __( 'Read More &raquo;', 'astra' ) );
    		$read_more_classes = apply_filters( 'astra_post_read_more_class', array() );
    
    		$post_link = sprintf(
    			esc_html( '%s' ),
    			'<a class="' . esc_attr( implode( ' ', $read_more_classes ) ) . '" href="' . esc_url( get_permalink() ) . '"> ' . the_title( '<span class="screen-reader-text">', '</span>', false ) . ' ' . $read_more_text . '</a>'
    		);
    
    		$output = ' &hellip;<p class="read-more"> ' . $post_link . '</p>';
    
    		return apply_filters( 'astra_post_link', $output, $output_filter );
    	}
    }
    add_filter( 'excerpt_more', 'astra_post_link', 1 );

    And wrote my code:

    function my_excerpt_more( $more ) {
     $read_more_text    = apply_filters( 'astra_post_read_more', __( 'Read More &raquo;', 'astra' ) );
        return ' <a class="my-read-more" href="'. get_permalink( get_the_ID() ) . '">' . $read_more_text . '</a>';
    }
    add_filter( 'excerpt_more', 'my_excerpt_more' );

    But now <p class = “read-more”> is missing. Help, please write the function correctly.
    I just wanted to know why the link does not have a class … I do not need to add it, but maybe it will be useful to someone. Thanks!
    For example, like this:

    function my_excerpt_more( $more ) {
     $read_more_text    = apply_filters( 'astra_post_read_more', __( 'Read More &raquo;', 'astra' ) );
        return ' <p class="read-more"><a class="my-read-more" href="'. get_permalink( get_the_ID() ) . '">' . $read_more_text . '</a></p>';
    }
    add_filter( 'excerpt_more', 'my_excerpt_more' );

    But I don’t know if it will be right

    Hello @zabavljaev

    The class is attribute has been kept empty intentionally.

    While if notice we have provided a filter – astra_post_read_more_class, which can be used to insert extra classes by the users.

    Just for your information, the empty class attribute won’t cause any issues. Also, we have made note of the same, so that when the class attribute is empty it won’t be displayed. This will be taken care of in future updates. 🙂

    I hope that helps and clarifies your query.

    Regards,
    Suman

    Thanks so much for such a detailed explanation!

    I wrote a filter that added a class to the a tag. But you are right: an empty attribute does not interfere. Perhaps it does not need to be hidden if it is not set.

    You’re most welcome, @zabavljaev

    We will look into it accordingly.

    Do let us know if there is anything else we can help you with.

    Regards,
    Suman

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