WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Link Post format Title in single.php (2 posts)

  1. Publishink
    Member
    Posted 1 year ago #

    I have set up a custom field to capture external links for use on my link post format.

    On the link post format itself the custom field is used as the href for the title. My problem arises when it comes to single.php. I've tried the code below to try to retain the link on the title of the post while not linking the standard posts.

    It doesn't work, and my guess is that the php code is all wrong (my knowledge here is very limited and it's something I'm working on). Any suggestions appreciated.

    ` <?php if ( has_post_format( 'post-format-link' , $post_id ) { ?>

    <h1><a href="<?php echo get_post_meta($post->ID, "ext_link", true); ?>" target="_blank"><?php the_title(); ?></a></h1>

    <?php } else { ?>

    <h1><?php the_title(); ?></h1>

    <?php } ?>`

  2. Publishink
    Member
    Posted 1 year ago #

    Resolved myself. Code that works is:

    <?php if ( has_post_format( 'link' )) { ?>
    
    <h1><a href="<?php echo get_post_meta($post->ID, "ext_link", true); ?>" target="_blank"><?php the_title(); ?></a></h1>
    
    <?php } else { ?>
    
    <h1><?php the_title(); ?></h1>
    
    <?php } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic