[resolved] Shortcode Of A Custom Field (3 posts)

  1. antonel1
    Posted 3 years ago #

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

  2. vtxyzzy
    Posted 3 years ago #

    Please explain more what you want, with one or two examples.

  3. antonel1
    Posted 3 years ago #

    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)

Topic Closed

This topic has been closed to new replies.

About this Topic