Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created September 19, 2017 20:52
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/01a5c8192af01cc7987cf15264f1c27e to your computer and use it in GitHub Desktop.
Save tripflex/01a5c8192af01cc7987cf15264f1c27e to your computer and use it in GitHub Desktop.
WP Job Manager Field Editor prepend Instagram URL to field value before output
<?php
// ^ the <?php above should only be in your functions.php file ONCE, at the top
// The filter is field_editor_output_as_value_METAKEY
// Below this example assumes the meta key is "company_instagram"
add_filter( 'field_editor_output_as_value_company_instagram', 'smyles_add_instagram_url_to_field_value', 10, 4 );
function smyles_add_instagram_url_to_field_value( $value, $meta_key, $listing_id, $args ) {
if ( empty( $value ) ) {
return $value;
}
// Only prepend when value does not already have instagram.com in it
if( strpos( $value, 'instagram.com' ) === FALSE ){
$value = 'https://www.instagram.com/' . esc_attr( $value );
}
return $value;
}
@tripflex
Copy link
Author

tripflex commented Nov 14, 2017

If you instead want to append a value (instead of prepend), here's an example of that:

// You should update METAKEY below to match your meta key, and ?ref=123 to whatever to append to end of value before it's output
add_filter( 'field_editor_output_as_value_METAKEY', 'smyles_append_something_to_value', 10, 4 );
function smyles_append_something_to_value( $value, $meta_key, $listing_id, $args ) {
	
        if ( empty( $value ) ) {
		return $value;
	}
	
        $value = $value . '?ref=123';
	return $value;
}

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