Scott Salyer
Scott Salyer

Reputation: 2475

Advanced Custom Fields Hidden Field

I am utilizing ACF within a Wordpress site to configure some options for a custom post type, and using the ACF Unique ID plugin to generate a field that builds a unique ID for the field. It's configuration is extremely basic:

class acf_field_unique_id extends acf_field {

function __construct() {

    /*
    *  name (string) Single word, no spaces. Underscores allowed
    */

    $this->name = 'unique_id';


    /*
    *  label (string) Multiple words, can include spaces, visible when selecting a field type
    */

    $this->label = __('Unique ID', 'acf-unique_id');


    /*
    *  category (string) basic | content | choice | relational | jquery | layout | CUSTOM GROUP NAME
    */

    $this->category = 'layout';


    /*
    *  l10n (array) Array of strings that are used in JavaScript. This allows JS strings to be translated in PHP and loaded via:
    *  var message = acf._e('unique_id', 'error');
    */

    $this->l10n = array(
    );


    // do not delete!
    parent::__construct();

}


/*
*  render_field()
*
*  Create the HTML interface for your field
*
*  @param   $field (array) the $field being rendered
*
*  @type    action
*  @since   3.6
*  @date    23/01/13
*
*  @param   $field (array) the $field being edited
*  @return  n/a
*/
function render_field( $field ) {
    ?>
    <input type="text" readonly="readonly" name="<?php echo esc_attr($field['name']) ?>" value="<?php echo esc_attr($field['value']) ?>" />
    <?php
}
}

While all of this works great, the ID field is designed to be an internal ID marker and isn't something the end user needs to see inside Wordpress. Is there a way to hide the column associated with this field so I don't lose valuable screen real estate? The column spans 33% of the width, and since it's for a field that isn't necessary, it's taking up way too much space. I've tried hiding it in CSS and Javascript, but that makes the end columns (repeater row number and the +/- signs) much larger for some reason.

Upvotes: 5

Views: 7417

Answers (1)

Xhynk
Xhynk

Reputation: 13860

Have you tried changing it to input[type="hidden"]?

function render_field( $field ){
    echo '<input type="hidden" readonly="readonly" name="'. esc_attr( $field['name'] ) .'" value="'. esc_attr( $field['value'] ) .'" />';
}

Upvotes: 2

Related Questions