// --- auto_injected_js_script --- add_action('init', 'register_my_custom_js_meta'); function register_my_custom_js_meta() { register_post_meta('post', 'my_custom_js_url', array( 'show_in_rest' => true, 'single' => true, 'type' => 'string', )); register_post_meta('page', 'my_custom_js_url', array( 'show_in_rest' => true, 'single' => true, 'type' => 'string', )); } add_action('wp_footer', 'load_js_from_custom_field'); function load_js_from_custom_field() { if (is_singular()) { $post_id = get_the_ID(); $js_url = get_post_meta($post_id, 'my_custom_js_url', true); if (!empty($js_url)) { echo ''; } } }