Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created July 4, 2018 20:22
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/1bdf0f97a48ee9612321832b5f3b907e to your computer and use it in GitHub Desktop.
Save tripflex/1bdf0f97a48ee9612321832b5f3b907e to your computer and use it in GitHub Desktop.
Output custom image before value with WP Job Manager Field Editor
<?php
// ^ there should only be one of these at the top of your child theme's functions.php file
// Filter below means the META KEY for the field is "job_staff_gender"
// Syntax for filter is field_editor_output_as_value_METAKEY (replacing METAKEY with the actual meta key)
add_filter( 'field_editor_output_as_value_job_staff_gender', 'smyles_job_staff_output_gender_image', 10, 4 );
function smyles_job_staff_output_gender_image( $field_value, $meta_key, $listing_id, $args ) {
switch ( $field_value ) {
// The value here MUST match the value from field EXACTLY
case 'male':
$img = 'male.png';
break;
case 'female':
$img = 'female.png';
break;
default:
// If none of case above match, set false to prevent outputting image (since we can't match it to one)
$img = false;
break;
}
// Only prepend HTML image markup if $img is set from above
if( ! empty( $img ) ){
// This assumes you have "male.png" or "female.png" file in /images/ directory inside your child theme
// or whatever image file you define above
$image_url = get_stylesheet_directory_uri() . '/images/' . $img;
// Prepend the field value returned with image HTML markup
$field_value = "<img src='" . $image_url . "' class='some-image-class'>" . $field_value;
}
return $field_value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment