This little function will allow you to add custom field’s data to your pages or posts content, useful for when you want to include a <script> tag into a post but don’t want to lose it when editing with the rich editor for example.

In your functions.php add this:

function customFieldShortcode ($atts) {
    extract(shortcode_atts(array('post_id' =&gt; NULL,), $atts));
    if (!isset($atts[0])) return;
    $field = esc_attr($atts[0]);
    global $post;
    $post_id = (NULL === $post_id) ? $post-&gt;ID : $post_id;
    return get_post_meta($post_id, $field, true);
add_shortcode('cfield', 'customFieldShortcode');

Now you can add a custom field to your page/post, for this example I’ll call the field “js” and put a script tag in it:

Custom Field Shortcode

And then all you need to do is write this in your page/post content:

[cfield "js"][/cfield]