Created
June 24, 2020 21:41
-
-
Save polevaultweb/1ae2fe3524d0606a2bebea6d73066d2d to your computer and use it in GitHub Desktop.
Add this to the wp-content/mu-plugins directory (create if doesn't exist)
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 | |
function my_igp_post_title( $title ) { | |
// "car model:", "engine:", "Country & City: and (no. 40)" ie.: | |
// Title: BMW E46 - M52 - Germany/Bavaria/Hof (no. 40) | |
$model = trim( get_string_between( $title, 'car model:', 'engine:' ) ); | |
$engine = trim( get_string_between( $title, 'engine:', 'bhp:' ) ); | |
$country = trim( get_string_between( $title, 'country & city:', 'occupation:' ) ); | |
$number = '(no. ' . trim( get_string_between( $title, ' (no.', ')' ) ) . ')'; | |
if ( ! empty( $model ) ) { | |
return $model . '- ' . $engine . '- ' . $country . $number; | |
} | |
return preg_replace( '/[[:^print:]]/', '', $title ); | |
} | |
function get_string_between( $string, $start, $end ) { | |
$string = ' ' . $string; | |
$ini = stripos( $string, $start ); | |
if ( $ini == 0 ) { | |
return ''; | |
} | |
$ini += strlen( $start ); | |
$len = stripos( $string, $end, $ini ) - $ini; | |
return substr( $string, $ini, $len ); | |
} | |
add_filter( 'igp_post_title', 'my_igp_post_title' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment