0

I added a custom field to a repeater with PHP:

        [
            'key' => 'field_sponsor_badge_url',
            'name' => 'url',
            'label' => 'URL',
            'type' => 'link',
        ],

due to the fact that it is a link field, when a user clicks it, a popup window shows with a checkbox for open link in new tab:

how do I hide this little subfield by adding a new entry to the array that creates the field?

And not: https://stackoverflow.com/questions/28821028/remove-open-link-in-a-new-window-tab-checkbox-in-post-link-visual-editor because I am only trying to hide the checkbox for this particular link field, that solution will hide all of them everywhere. I am not trying to hide all of those checkboxes for every link field on the page either.

2
  • That dialog box is built-in to WordPress and is functionally unrelated to ACF. I'd remove the part about ACF as it's unrelated to the question, and could be flagged as off-topic, since third-party plugin support is off-topic here.
    – YourManDan
    Aug 9, 2023 at 20:24
  • ok thanks yeah I did
    – steve8094
    Aug 9, 2023 at 20:50

1 Answer 1

0

Site-Wide Checkbox Hide

You can add a simple function to your functions.php to change its visibility (and will also set the default checked state to false):

function disable_open_new_window() {
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function ($) {
            $('input#link-target-checkbox').prop('checked', false);
            $('#wp-link .link-target').css('visibility', 'hidden');
        });
    </script>
    <?php
}
add_action ('after_wp_tiny_mce', 'disable_open_new_window');

This will change the visibility of that checkbox site-wide, however, as the dialog box is not specific to ACF, and is used a few places in WordPress.

Reference: Prevent WordPress Authors From Setting Links to Open in New Windows

Field-Specific Checkbox Hide

As far as I'm aware, this isn't possible, since the dialog box isn't specific to custom fields (or ACF), it's a WordPress built-in dialog box.

Instead of hiding the checkbox, you can make it functionally useless instead. If you take a look at the documentation, you'll see you can retrieve a $link['target'] option, which you can choose to use, or set that field to _self or _blank or whatever you want it to be.

6
  • 1
    If you want to be even more WordPress-y, put the JS in its own file, then use the enqueue_script() function to load it.
    – YourManDan
    Aug 9, 2023 at 20:30
  • That is almost the solution but that is going to hide the checkbox everywhere on the whole site, I only want to hide it on one edit screen for one page only when this field is rendered
    – steve8094
    Aug 9, 2023 at 20:53
  • @steve8094 Like only when you're using the link ACF field?
    – YourManDan
    Aug 9, 2023 at 20:58
  • yes, I'm just trying to have this specific field render without that option. Is there maybe something I can add to that array?
    – steve8094
    Aug 9, 2023 at 21:02
  • @steve8094 No, there's no options in ACF for disabling that checkbox (through code or otherwise). I don't believe what you're asking for is possible, as the dialog box is built into WordPress, and all ACF is doing is showing the dialog box, and then retrieving information from it.
    – YourManDan
    Aug 10, 2023 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.