Created
September 19, 2017 20:52
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you instead want to append a value (instead of prepend), here's an example of that: