Last active
August 29, 2015 14:05
-
-
Save ericpedia/6c6f4bda33d5a7e0f2c2 to your computer and use it in GitHub Desktop.
WordPress: Remove date ranges from post titles
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 | |
/** | |
* Remove date ranges from post titles | |
* | |
* @author ericpedia | |
* @since 2014-08-26 | |
* | |
*/ | |
add_filter( 'the_title', 'epi_remove_dates_from_charts' ); | |
function epi_remove_dates_from_charts( $title ) { | |
global $post; | |
// $isChart = is_singular( array('chart', 'post') ); // no idea why this didn't work | |
$isChart = in_array( $post->post_type, array('chart', 'post') ); | |
if ( ! $isChart ) return $title; | |
$months = '((Jan(uary)?|Feb(ruary)?|Mar(ch)?|Apr(il)?|May|Jun(e)?|Jul(y)?|Aug(ust)?|Sep(t|tember)?|Oct(ober)?|Nov(ember)?|Dec(ember)?)\.?)'; | |
// @todo doesn't catch the years at the end of: "Change in real family income from business cycle peak years 1989, 2000, and" | |
$filtered = preg_replace( '/,? ('.$months.'?[\s-–—]?\d+([-–— and]+'.$months.'?[\s-–—]?\d+)?( \(.*dollars.*\))?\*?$)/', '', $title ); | |
// To privately test you can uncomment this | |
// if ( is_user_logged_in() ) { | |
// return "$title<br>$filtered"; | |
// // return "$title<br>$filtered"; | |
// } | |
return $filtered; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment