Support

Account

Home Forums Add-ons Options Page Hook after title ?

Solved

Hook after title ?

  • Hi,

    At the moment, every field I’ve set for my Options Page is display into 2 columns:
    * Title of the field
    * Field

    I would like to add the id of the field next to the title of the field.
    Is there any Filter available or another method to do that?

    thanks 🙂

  • What do you mean by ID?

    Yes, you can use an acf/prepare_field filter and you can alter the label of the field to include other information https://www.advancedcustomfields.com/resources/acf-prepare_field/

  • By ID I meant the name (not the label) of the field (used by functions).
    My plan is to add this data near the label to simplify my life 😀

    Thanks you so much !

  • I come back to this thread because I were able to change the label field per field..
    But I would like to apply this to all fields located in my Option page named: “Custom Options”.

    I own 47 fields and I add very often fields… that s going to take a lot of line if I have to write lines for every field.

    Any solution?

    thanks !

  • This is a little something that I have created so that I can see field information when I’m developing a site. This adds an information block to every field label that shows the field information when you hover over the label.

    
    add_action('acf/prepare_field', 'acf_add_field_details_for_display', 20);
    function acf_add_field_details_for_display($field) {
      if (!$field || 
          !acf_current_user_can_admin() || 
          get_post_type() == 'acf-field-group' ||
          !get_field('site_acf_field_info', 'options')) {
        return $field;
      }
      $html = ' <span class="acf-field-details"><span class="show-field-details dashicons dashicons-info" data-action="show-field-details"></span><span class="acf-field-details-block"><span>&nbsp;&nbsp;type: '.$field['type'].'</span>';
      if (isset($field['_name']) && $field['_name']) {
        $html .= '<span>&nbsp;&nbsp;name: '.$field['_name'].'</span>';
      }
      $html .= '<span>&nbsp;&nbsp;&nbsp;key: '.$field['key'].'</span>';
      if (isset($field['return_format']) && $field['return_format']) {
        $html .= 'return: '.$field['return_format'].'</span>';
      }
      $html.= '</span>';
      $field['label'] .= $html;
      return $field;
    }
    
    add_action('admin_head', 'acf_field_details_display');
    function acf_field_details_display() {
        // add field detials info for admins
        if (!function_exists('get_field') || !get_field('site_acf_field_info', 'options')) {
          // no acf
          return;
        }
        if (!acf_current_user_can_admin()) {
          return;
        }
        ?>
          <style type="text/css">
            .acf-field-details {
              font-weight: normal;
              position: relative;
            }
            .show-field-details {
              color: #ACD;
              font-size: 16px;
            }
            .acf-field-details-block {
              display: none;
              position: absolute;
              top: 0;
              left: 0;
              z-index: 9999;
              border-radius: 5px;
              color: #333;
              background-color: #ACD;
              padding: 5px;
              font-family: "Courier New", Courier, monospace;
              font-size: .9em;
            }
            .acf-field-details-block span {
              display: block;
              white-space: nowrap;
            }
            .acf-field-details:hover .acf-field-details-block {
              display: block;
            }
          </style>
        <?php 
      } // end function acf_field_details_display
    
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.