-
-
edjarrett
Yes, that is what it has always been. I am trying to change it to something like this
King Jesus
Acts 17:6-7At least a part of the problem with the code that Fernando provided is that the “dash” between Jesus and Acts is not a regular hyphen, although that is what I entered. I read last night before I quit for the day that WordPress converts a “space dash space” into a “space en-dash space”. I do not know PHP, so am struggling to find the right combination of functions to be able to split my title on the en-dash.
-
Yeah, you have to love WP for doing that
So in Fernandos code where you see'-'you can replace that with a unicodeIf its the
space en-dash spacethen you can use' \u2013 'in its place. -
edjarrett
Thanks. This is better. But it is now returning
King
ing Jesus – Acts 17:6-7 -
edjarrett
OK, I think I have this figured out. WordPress was displaying an en-dash in the title. But that is not what is encoded in the string passed to this function. Instead of “King Jesus – Acts 17:6-7”, it was “King Jesus – Acts 17:6-7”. I have to look at every character individually to discover that. So now I search for the & for the first part and jump over 7 characters for the second part. And that seemed to do the trick.
add_filter(‘generateblocks_dynamic_content_output’, function($content, $attributes, $block){
if ( !is_admin() && ! empty( $attributes[‘className’] ) ) {
if( strpos( $attributes[‘className’], ‘cu-post-title’ ) !== false ) {
$content = strtok($content, “&”);
} else if (strpos( $attributes[‘className’], ‘cu-post-sub-title’ ) !== false){
$content = substr($content, strpos($content, “&”) + 7);
} else {
return $content;
}}
return $content;
}, 10, 3); -
edjarrett
I realized that if I had a & in my title, that I would have problems with the code above. So I changed it to below, and it still works. Thanks for all your help with this.
add_filter(‘generateblocks_dynamic_content_output’, function($content, $attributes, $block){
if ( !is_admin() && ! empty( $attributes[‘className’] ) ) {
if( strpos( $attributes[‘className’], ‘cu-post-title’ ) !== false ) {
$content = strtok($content, “–”);
} else if (strpos( $attributes[‘className’], ‘cu-post-sub-title’ ) !== false){
$content = substr($content, strpos($content, “–”) + 7);
} else {
return $content;
}}
return $content;
}, 10, 3); -
Well that was kind of a uphill battle, as these kinds
dashreplacements seem to always create. But i am glad to see you found one that works! -
edjarrett
Yes it was. I did test this with a post title that had an & in it. And it broke there. So I replaced the & with the word “and” and will just try and remember that I cannot use that symbol in titles any longer.
Thanks again for your help. Not sure I would have made it without the original code snippet.
-
Fernando
Glad you found a solution. You’re welcome!
- You must be logged in to reply to this topic.
