Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created December 6, 2017 23:25
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/04f4fa05726ce9f5aa5d20518c67cd82 to your computer and use it in GitHub Desktop.
Save tripflex/04f4fa05726ce9f5aa5d20518c67cd82 to your computer and use it in GitHub Desktop.
Output script tag with URL from a field value when using WP Job Manager Field Editor
<?php
// ^ the <?php above should only be in your functions.php file ONCE, at the top
// Because sanitation strips out script tags, if you want to output a custom script tag, you can use this filter to only have to specify the URL in a field
// The filter is field_editor_output_as_value_METAKEY
// Below this example assumes the meta key is "some_script_url"
add_filter( 'field_editor_output_as_value_some_script_url', 'smyles_output_some_custom_script_tag', 10, 4 );
function smyles_output_some_custom_script_tag( $value, $meta_key, $listing_id, $args ) {
// Do not want to output if a value does not exist
if ( empty( $value ) ) {
return $value;
}
$output = '<script type="text/javascript" src="' . $value . '"></script>';
return $output;
}
@tripflex
Copy link
Author

tripflex commented Dec 6, 2017

Example surfline widget output:
https://gist.github.com/tripflex/01500fd95c0beedb69b40dd95d17b9bb

When configuring the auto output, you should set the output to VALUE ONLY (not standard)

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