• Resolved tommysvr

    (@tommysvr)


    Hi,

    I’m trying to setup my articles so that if I put a link to a PDF in a custom field, it replaces the permalink of the title.

    Eg:

    <?php if ( get_post_meta($post->ID, 'title-link', true) ) : ?>
    <h2><a href="<?php echo get_post_meta($post->ID, 'title-link', true) ?>"><?php the_title(); ?></a></h2>
    <?php endif; ?>

    However, what I would also like is if the custom field ‘title-link’ doesn’t have a value, for it to just be the_permalink();

    Does anyone have any tips? I’ve tried with else, elseif but nothing seems to be working.

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I believe this should work:

    <?php if ( $title_link = get_post_meta($post->ID, 'title-link', true) ) : ?>
       <h2><a href="<?php echo $title_link; ?>"><?php the_title(); ?></a></h2>
    <?php else: ?>
       <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php endif; ?>
    Thread Starter tommysvr

    (@tommysvr)

    Perfect! Thank you very much! ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘if else Help for Article Titles’ is closed to new replies.