Skip to content

Instantly share code, notes, and snippets.

@yratof
Created September 28, 2016 07:28
Show Gist options
  • Save yratof/0e3ec60617122a77bc12970af895efd8 to your computer and use it in GitHub Desktop.
Save yratof/0e3ec60617122a77bc12970af895efd8 to your computer and use it in GitHub Desktop.
Split titles at pipe
<?php
class f {
static function s() {
add_filter( 'the_title', __CLASS__ . '::split_product_title_at_pipe' );
}
static function split_product_title_at_pipe( $title ) {
if ( ! is_product() ) {
return $title;
}
// Split the title at a pipe
$substrings = explode( ' | ', $title );
$title = ( ! empty( $substrings[0] ) ) ? $substrings[0] . '<span class="title-byline">' . $substrings[1] . '</span>' : $title;
return $title;
}
}
f::s();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment