I know that WordPress can filter shortcodes like the_content
but is it possible to filter get_the_content
?
I have a function that is able to use substr
and strpos
and I know it works on the_title
. I tried the same thing for get_the_title
but I couldn't get it to work.
Is it possible for the same to work on get_the_title
?
Code I have so far:
function gg_short_title($title) {
// This can return false, so check there is something
$linkt=array();
$linkt[] = substr($title, 0, strpos($title, ' —'));
$linkt[] = substr($title, 0, strpos($title, ' –'));
$linkt[] = substr($title, 0, strpos($title, ' |'));
$linkt[] = substr($title, 0, strpos($title, ' -'));
$short_title = implode('', $linkt);
if ($short_title) {
return $short_title;
}
// Else just return the normal title
return $title;
}
add_filter('get_the_title', 'gg_short_title', 10, 1);
Thanks.
$linkt[] = substr($title, 0, strpos($title, ' —')); $linkt[] = substr($title, 0, strpos($title, ' –')); $linkt[] = substr($title, 0, strpos($title, ' |')); $linkt[] = substr($title, 0, strpos($title, ' -')); $linkt[] = substr($title, 0, strpos($title, ' —')); $linkt[] = substr($title, 0, strpos($title, ' |'));
—
, etc)?