Skip to content

Instantly share code, notes, and snippets.

@grayayer
Created March 16, 2026 17:58
Show Gist options
  • Select an option

  • Save grayayer/1dfa56478225466156b234567fd9f393 to your computer and use it in GitHub Desktop.

Select an option

Save grayayer/1dfa56478225466156b234567fd9f393 to your computer and use it in GitHub Desktop.
Add paragraph break after colon in post titles on wordpress single post pages.
/**
* Add paragraph break after colon in post titles on single post pages.
*
* @param string $title The post title.
* @return string Modified title with paragraph break after colon if applicable.
*/
function modify_post_title_with_colon( $title ) {
// Only modify title on single post pages.
if ( is_single() && in_the_loop() && is_main_query() ) {
// Replace colon with colon + paragraph break.
return str_replace( ':', ':<br>', $title );
}
return $title;
}
add_filter( 'the_title', 'modify_post_title_with_colon' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment