高级自定义字段隐藏字段

Rub*_*aus 5 wordpress advanced-custom-fields

我在 Wordpress 站点中利用 ACF 为自定义帖子类型配置一些选项,并使用 ACF 唯一 ID 插件生成一个字段,该字段为该字段构建唯一 ID。它的配置非常基本:

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
}
}
Run Code Online (Sandbox Code Playgroud)

虽然所有这些都很有效,但 ID 字段被设计为内部 ID 标记,并不是最终用户需要在 Wordpress 中看到的内容。有没有办法隐藏与此字段关联的列,这样我就不会失去宝贵的屏幕空间?该列占宽度的 33%,由于它用于不需要的字段,因此占用了太多空间。我尝试将其隐藏在 CSS 和 Javascript 中,但是由于某种原因,这使得末尾列(重复器行号和 +/- 符号)变得更大。

Xhy*_*ynk 2

您尝试过将其更改为吗input[type="hidden"]

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