Skip to content

Instantly share code, notes, and snippets.

@nickcernis
Last active April 23, 2019 07:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickcernis/77e0a33aaaf6ac14e57f0d105e8b47ee to your computer and use it in GitHub Desktop.
Save nickcernis/77e0a33aaaf6ac14e57f0d105e8b47ee to your computer and use it in GitHub Desktop.
Link Genesis post title directly to content when using the Link post format
add_filter( 'genesis_post_title_output', 'sp_link_post_format_title' );
/**
* If the post uses the “Link” post format and has a URL in the content,
* link the title directly to that URL instead of to the post itself.
*
* @param string $title_html The original title HTML.
* @return string The updated HTML.
*/
function sp_link_post_format_title( $title_html ) {
if ( get_post_format() !== 'link' ) {
return $title_html;
}
$url_in_content = get_url_in_content( get_the_content() );
if ( $url_in_content ) {
return preg_replace('/<a(.*)href="([^"]*)"(.*)>/','<a$1href="' . $url_in_content . '"$3>', $title_html );
}
return $title_html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment