Support

Account

Home Forums Backend Issues (wp-admin) Simple URL Field

Solved

Simple URL Field

  • Hi there! I’m creating backend interface and one of the things I’d like to display is a simple link that is associated with the post:

    https://drive.google.com/open?id=1ACe2weLzdWI_29_3TEbPcUEKW37vK_cy

    I’ve done that with the link field but it’s a bit of an overkill for what the purposes are. I just want something that the user can click (but not edit) and will take them to that link in the *same* browser window.

    I thought about using jQuery to modify the link field but there has got to be an easier way to do this…would you please point me in the right direction?

    Thanks!

  • Hi,

    I’m not sure, but you could probably use the “acf/load_field” filter.
    https://www.advancedcustomfields.com/resources/acf-load_field/

    And a small function like :

    function read_only_field($field) {
    $field[‘readonly’] = true;
    return $field;
    }
    add_filter(‘acf/load_field’, ‘read_only_field’);

    You could target your field using the filter :

    add_filter(‘acf/load_field/name=field_name’, ‘read_only_field’);
    add_filter(‘acf/load_field/key=field_key’, ‘read_only_field’);

  • Thanks, the readonly field does not affect the link field. I went ahead and wrote this jQuery to get rid of the buttons and make link load on the same window:

    function hideEditRemoveLinkButtons($) {
        $('.link-wrap > .-pencil').remove();
        $('.link-wrap > .-cancel').remove();
    }
    
    function changeLinkTargetToSelf($) {
        $('.link-url').attr('target','_self')
    }
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Simple URL Field’ is closed to new replies.