Skip to content

Instantly share code, notes, and snippets.

@slimndap
Created October 18, 2015 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slimndap/5ddb7c4e32d746691849 to your computer and use it in GitHub Desktop.
Save slimndap/5ddb7c4e32d746691849 to your computer and use it in GitHub Desktop.
Add a 'Director: ' label in front of a custom 'director' production field. For use inside the functions.php of your theme.
<?php
/*
* Adds a 'Director: ' label in front of a custom 'director' production field.
* @param string $value The value for the 'director' field.
* @param string $field The custom field name.
* @param WPT_Production $production The production.
* @return string The updated value for the 'director' field.
*/
function wpt_add_director_label($value, $field, $production) {
if (!empty($value)) {
$value = 'Director: '.$value;
}
return $value;
}
add_filter('wpt_production_director', 'wpt_add_director_label', 10, 3);
@slimndap
Copy link
Author

When using a plugin like Simple Fields, the custom field names may look different (eg. _simple_fields_fieldGroupID_1_fieldID_1_numInSet_0). In that case the code looks like this:

<?php
  /*
   * Adds a 'Director: ' label in front of a custom 'director' production field.
   * @param   string          $value      The value for the 'director' field.
   * @param   string          $field      The custom field name.
   * @param   WPT_Production  $production The production.
   * @return  string                      The updated value for the 'director' field.
   */
  function wpt_add_director_label($value, $field, $production) {
    if (!empty($value)) {
      $value = 'Director: '.$value;
    }
    return $value;
  }
  add_filter('wpt_production__simple_fields_fieldGroupID_1_fieldID_1_numInSet_0', 'wpt_add_director_label', 10, 3);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment