clubmate.fi

A good[ish] website

Web development blog, loads of UI and JavaScript topics

Give each excerpt a unique class in WordPress

Filed under: WordPress— 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>';
}

Usage:

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

Comments would go here, but the commenting system isn’t ready yet, sorry. Tweet me @hiljaa if you want to make a correction etc.

  • © 2021 Antti Hiljá
  • About
  • Follow me in Twatter → @hiljaa
  • All rights reserved yadda yadda.
  • I can put just about anything here, no one reads the footer anyways.
  • I love u!