A good[ish] website

Web development blog, loads of UI and JavaScript topics

Give each excerpt a unique class in WordPress

Filed under: WordPress/PHP— Tagged with: snippets, php

Giving an excerpt an unique class may come handy when writing CSS in BEM style. Here's a small function to do that.

This goes into your function.php file:

function cm_excerpt( $class ) {
  $excerpt = strip_tags( get_the_excerpt() );
  echo '<p class="' . $class . '">' . $excerpt . '</p>';


<?php excerpt('article__excerpt'); ?>

Comments would go here, but the commenting system isn’t ready yet, sorry.

  • © 2022 Antti Hiljá
  • About
  • All rights reserved yadda yadda.
  • I can put just about anything here, no one reads the footer anyways.
  • I love u!