Home Forums General Issues Anchor links referring to itself


Anchor links referring to itself

  • I created a text field “website”

    here is my code

    <p><a href="<?php the_field('web_address');?>" target="_blank" ><?php the_title(); ?> Website </a></p>

    works fine, except when the field is blank — then the link is automatically set to the page URL

    is this a WordPress issue or a custom fields issue

  • Well, either set the field “web_address” to “required” or check for existence of the field first before creating the paragraph with the link.

    <?php if (get_field('web_address')) { ?>
      // your code
    <?php } ?>

    And I don’t think the link is to the page URL when not filled out in the backend, it’s probably just empty. Try this:

    echo get_field('web_address')

    And you should get nothing for an empty field.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.