I'm developing a site where better is very quickly becoming the enemy of the good.

I would like to make updating as simple for the client as possible by enabling them to populate boilerplate and images text using a shortcode. However, there is one word within the boilerplate text which needs to be unique for each page and must be added by the client. I was thinking of using a specific custom field key and value, as a way of capturing the unique information.

Is it possible and reasonable to use custom fields for this purpose within the shortcode? I'm having trouble thinking through the syntax. Is there a better way to do this?

2 Answers 2


Not sure I understand your specifics, add details if I am off. I assume:

  1. Your shortcode inside post's content.
  2. You have custom field in that post with value you want.

In this case declare in your shortcode function global $post; and use $post->ID to retrieve custom field.

  • You are on the right track. Essentially the shortcode contains the entire content for the page (text, images, etc), with the exception of the variable piece that the end user must enter. Think of something like a diploma, where the variable part is the student's name. I'm just having problems retrieving the custom-field data. Since you suggest it can be done, I just have to work through it. I'm self-taught and I haven't written that chapter yet. ;) Apr 1, 2011 at 16:48
  • @Ray Mitchell had you got to post's ID as I suggested? If you have that then it's easy to retrieve custom field value with get_post_meta().
    – Rarst
    Apr 1, 2011 at 16:55
  • I'm going down that path. This is the first time that I'll be using both shortcodes and custom-fields in a project, so I'm working out the kinks for both of them, then trying to combine. If you can point to some resources (beyond the codex) on using custom-fields I'd appreciate it. Apr 1, 2011 at 17:01
  • Rather than using the custom-field, I'll use attributes in the shortcode. So instead of a simple shortcode - [example], the client will enter the shortcode [example value1="AAA" value2="BBB"]. Thanks for the suggestion Apr 2, 2011 at 0:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.