Created
September 28, 2016 07:28
-
-
Save yratof/0e3ec60617122a77bc12970af895efd8 to your computer and use it in GitHub Desktop.
Split titles at pipe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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