• Hello all,

    I would like to create a custom post

    media-id

    Lets say media-id is assigned the number 12345

    I’d, then, like to put in my post, something like the following:

    The media-id for this post is [media-id].

    How would I assign a custom field to a bracket?

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • create a shortcode calling to your custom field

    https://www.problogdesign.com/wordpress/working-with-wordpress-shortcodes/

    To be able to insert a bracketed value into the create post box, you’ll need to do some editing to the page(s) that display the post to the user. You’d replace the_content with something like this (adjusting the code as necessary).

    $content = get_the_content();
    $mediaID = get_post_meta($post->ID, 'media-id', true);
    $content = str_replace('[media-id]', $mediaID, $content);
    echo($content);

    I’d suggest only doing this on single posts, rather than in the front page or the archives, as it will slow loading down a bit.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display Custom Field ANYWHERE in post.’ is closed to new replies.