• Resolved Chris

    (@pma4life)


    Hello there, very nice plugin. I am having an issue where, regardless of target selection(same or new window), the link opens in a new window. Both internal and external links perform this way. Looking at the page source, the element renders with ‘target=”0″‘ or ‘target=”1″‘. Not sure if that has anything to do with it.

    Any assistance would be greatly appreciated Thanks!

    https://www.ads-software.com/plugins/acf-link/

Viewing 1 replies (of 1 total)
  • Plugin Author Corey Worrell

    (@coreyw)

    Hello @pma4life,

    The field is saved in the database as either a “0” (same window/tab) or “1” (new window/tab), and it is the developers responsibility to use that how they see fit. For example:

    <?php
    $link = get_field('link');
    $target = $link['target'] ? ' target="_blank"' : '';
    $a = sprintf('<a href="%s"%s>Link</a>', $link['url'], $target);

    Or you could always add a filter to format the target how you like. Example:

    add_filter('acf/format_value/type=link', function ($value, $post_id, $field) {
      $value['target'] = $value['target'] ? '_blank' : '_self';
      return $value;
    }, 10, 3);
    
    $link = get_field('link');
    printf('<a href="%s" target="%s">%s</a>', $link['url'], $link['target'], $link['title']);
Viewing 1 replies (of 1 total)
  • The topic ‘Link opens in new tab regardless of selection’ is closed to new replies.