Title Link for the WordPress Post Format Link

Post Formats was introduced into WordPress in version 3.1. A Post Format is a piece of meta information that can be used by a theme to customize its presentation of a post. Using the “link” post format, your blog can link to another website or blog. If your theme does not support link post format, I’m going to show you how to easily customize that theme to support it.First, open your theme’s functions.php. Look for the following code or something similar to it:

add_theme_support('post-formats', ['aside', 'gallery', 'link', 'image', 'quote', 'video', 'audio']);

If you can not find the code or something similar to it, add the following to your theme’s functions.php:

// Enable post formats
// http://codex.wordpress.org/Post_Formats
add_theme_support('post-formats', ['aside', 'gallery', 'link', 'image', 'quote', 'video', 'audio']);

If there is something like the code above, but doesn’t contain the link part, then add it, making sure it’s wrapped in singular quotes and followed by a comma.

You can also sign in to your WordPress dashboard and edit a post or create a post. Look on the right side for a box entitled “Format” and look for an option under it called “Link.”

Post Format Box

Next, in your functions.php file, add the following code snippet:

// Get post format title link
if ( ! function_exists( 'post_format_link_url' ) ) :
function post_format_link_url() {
    $has_url = get_url_in_content( get_the_content() );

    return $has_url ? $has_url : apply_filters( 'the_permalink', get_permalink() );

Now, open all of your archive index templates, such as index.php, archive.php, tags.php and category.php.

Now look for the post heading title in these templates, most likely will be in <h1></h1> or <h2></h2> HTML tags. Replace the heading title with the following:

    if ( has_post_format( 'link' )) {
        the_title( sprintf( '<h2 class="entry-title"><a href="%s" target="_blank" rel="nofollow">', esc_url( post_format_link_url() ) ), '</a></h2>' );
    else {
        the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' );

You’re done! Make sure when you are creating your posts, that you select “Link” as the Format.