Skip to content

Instantly share code, notes, and snippets.

@tripflex
Last active June 21, 2019 20:29
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 tripflex/574972b93c42600cf487ec8ca27ee9fd to your computer and use it in GitHub Desktop.
Save tripflex/574972b93c42600cf487ec8ca27ee9fd to your computer and use it in GitHub Desktop.
Output FontAwesome icon instead of field value when using WP Job Manager Field Editor
<?php
// ^ there should only be one of these at the top of your child theme's functions.php file
// Syntax for filter is field_editor_output_as_value_METAKEY (replacing METAKEY with the actual meta key)
// MAKE SURE YOU REPLACE "METAKEY" below to match the meta key of the field you want to use this for!
add_filter( 'field_editor_output_as_value_METAKEY', 'smyles_output_font_awesome_icon_for_value', 10, 4 );
function smyles_output_font_awesome_icon_for_value( $field_value, $meta_key, $listing_id, $args ){
if( empty( $field_value ) || is_array( $field_value ) ){
return $field_value;
}
$field_value = esc_attr( $field_value );
// This will output the HTML below, using the value from the field to determine the icon to use,
// just make sure that it matches exactly what fontawesome expects it to be
return "<i class=\"fab fa-{$field_value}\"></i>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment