Site logo

Archived topic

Applying CSS to hook content

6 replies · Started by David on April 21, 2017

Viewing posts 1–7 of 7

Hi Tom and team,

im a little out of depth here, i have cobbled together the below PHP snippet which puts the product (post) excerpt into the shop loop. Now i dont know how to style the excerpt using CSS. I have looked at creating DIV and Classes etc but thats beyond me.

Any ideas? If not i am going to through it at woo. BTW the PHP works but again if there is anything amiss or could be trimmed down your advice would be much appreciated.


/* 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 apply_filters( 'woocommerce_short_description', $post->post_excerpt );
	}
}

You could try something like this:

/* 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="my-selector">' . apply_filters( 'woocommerce_short_description', $post->post_excerpt ) . '</div>';
	}
}

Then you can style it with:

.my-selector {}

thanks Tom - as usual you make it so damn easy (and so obvious!)

Hi Tom

could you help, the post excerpt is a variable length, i want to limit the number of characters or words displayed in the .my-selector. Any ideas?

Thanks Tom - case closed

You're welcome :)

This archived topic is closed to new replies.