Site logo

Archived topic

Is it possible to include a "Read more" function with this code

5 replies · Started by Tor on June 1, 2018

Viewing posts 1–6 of 6

Hi thanks to Tom I found and added this code:

/* Adding excerpt to shop page */
add_action( 'woocommerce_after_shop_loop_item', 'diggs_custom_shop_item', 5);
function diggs_custom_shop_item() {
	global $post;
		/* product excerpt  */
	if ( $post->post_excerpt ) {
		echo '<div class="diggs-shop-excerpt">' . apply_filters( 'woocommerce_short_description', wp_html_excerpt($post->post_excerpt,100,'... ') ) . '</div>';
	}
}

Is it possible to add a "Read more" function to the Excerpt?

Thanks

Hi there,

Not quite sure if I understand.

Where are trying to add read more?

Give this a shot:

add_action( 'woocommerce_after_shop_loop_item', 'diggs_custom_shop_item', 5);
function diggs_custom_shop_item() {
	global $post;
		/* product excerpt  */
	if ( $post->post_excerpt ) {
		echo '<div class="diggs-shop-excerpt">' . apply_filters( 'woocommerce_short_description', wp_html_excerpt($post->post_excerpt,100,'... ') ) . '</div>';

                echo '<p><a href="' . get_permalink( $post->ID ) . '" class="button">Read more</a></p>';
	}
}

Let me know :)

Thanks Tom, I rebuilt it a bit ;-)

add_action( 'woocommerce_after_shop_loop_item', 'diggs_custom_shop_item', 5);
function diggs_custom_shop_item() {
	global $post;
		/* product excerpt  */
	if ( $post->post_excerpt ) {
		echo '<div class="diggs-shop-excerpt">' . apply_filters( 'woocommerce_short_description', wp_html_excerpt($post->post_excerpt,80,'<a href="' . get_permalink( $post->ID ) . '"><strong>...Les mer</strong></a>') ) . '</div>';
	}
}

Perfect :) Thanks for sharing!

This archived topic is closed to new replies.