Last active
April 23, 2019 07:21
-
-
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
This file contains 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
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