WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Shortcode Of A Custom Field

[Resolved] Shortcode Of A Custom Field

  • Is it possible to create a shortcode of a custom field? If so, does anyone know of an example I can use?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Please explain more what you want, with one or two examples.

    Okay, I was able to figure it out using the method provided from this link.

    This is how you can turn a custom-field into a shortcode which can be placed anywhere in the content of a post.

    – First make a custom field titled ‘sub-title’.

    – Then insert this code into functions.php

    function shortcodefunction() {
    	global $post;
    	return get_post_meta($post->ID, 'sub-title', true);
    }
    add_shortcode('sub-title-function', 'shortcodefunction');

    – Then insert [sub-title-function] above the text in your post.

    Done! Hopefully someone will find this tip useful someday!

    Thanks vtxyzzy for considering to help me anyway! :o)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Shortcode Of A Custom Field’ is closed to new replies.
Skip to toolbar