This plugin hasn’t been tested with the latest 3 major releases of WordPress. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.

Conditional Custom Fields Shortcode


A series of shortcodes for using custom field values in pages or posts (or in sidebar widgets – via Section Widget!), which would then allows you to take store the actual data in custom fields while storing the presentation in the page/post body. This transforms WordPress into an awesome CMS. Keep reading for more inspirations.

Basic Usage



<pre><code>Picture of the day:
&lt;img src='[cf "picture-link"]' /&gt;

<p>This would output something like <code>&lt;img src='' /&gt;</code>, assume the post/page has the custom field "picture-link" and its value is "". That way, you (or your clients!) would never accidentally take out a div when updating your page because you won't have to touch the page/post body anymore!</p>

<h4>Default Values</h4>

<pre><code>[cf "custom field name" default="display this if the CF is undefined"]


<pre><code>Contact [cf "support-email" default=""] if you have questions.

<p> will be displayed there if the custom field "support-email" is not present in that post/page.</p>

<h4>Simple Template</h4>

<pre><code>[cf "custom field name" default="default value"]...template...



If you cannot use %value% as your placeholder text for some reason, you can change it by specifying the placeholder attribute.



Multiple Values

It’s smart enough to do the right thing. If your post has the following custom fields:

  • concert-date: Jan 14th
  • concert-date: Jan 28th
  • concert-date: Feb 2nd


</code> will output <code>Jan 14th,Jan 28th,Feb2nd</code>, exactly what you would expect. You can also optionally provide a separator to replace the default (,).</p>


<pre><code>Come to one of our concerts on the following dates: [cf "concert-date" separator=" / "]

<p>(=&gt; Jan 14th / Jan 28th / Feb 2nd)</p>


<pre><code>[cf "custom field name" sort="nosort|asc|dsc|random" type="string|int|integer|float|bool|boolean|date|auto"]

<p>You can control how it sort the items (when there's more than one) using the sort attribute (default is <code>nosort</code>). By default, it would compare them using PHP's comparison operator (i.e. try to cast them into numeric values, or compare them as strings if that failed). However, you can force a type cast by specifying the type attribute (default is <code>auto</code>).</p>

<h4>Display Single Value</h4>

<p>If display multiple values is not what you want it to do, you can use <code>[cf single="true"]</code> to force it to display only the first value. Combining what we have learned so far, you can display a single random value by <code>[cf single="true" sort="random"]</code>.</p>


<p>Syntax for <code>[cf]</code> shortcode: (default values in parenthesis)</p>

<pre><code>[cf "field-name" default="" placeholder="%value%" single="(false)|true" separator="," sort="(nosort)|asc|dsc|random" type="string|int|integer|float|bool|boolean|date|(auto)"](OPTIONAL) template


Conditionals tags is what makes this plugin unique. Here is a list of them:

[if-cf-def "custom field name"]
  Do this when "custom field name" is defined for this page/post

[if-cf-ndef "custom field name"]
  Do this when "custom field name" is NOT defined for this page/post

[if-cf-eq "custom field name" "value"]
  Do this when "custom field name" == "value"

[if-cf-neq "custom field name" "value"]
  Do this when "custom field name" != "value"

[if-cf-lt "custom field name" "value"]
  Do this when "custom field name" < "value"

[if-cf-gt "custom field name" "value"]
  Do this when "custom field name" > "value"

[if-cf-let "custom field name" "value"]
  Do this when "custom field name" <= "value"

[if-cf-get "custom field name" "value"]
  Do this when "custom field name" >= "value"

More detailed documentations will be published soon. In the mean time, check out the following examples and the comments in the PHP code to get a rough idea.


[if-cf-get "deadline" "today" type="date"]
    Submit your application <a href='

[if-cf-lt "deadline" "today" type="date"]
    Sorry we regret that we cannot take anymore applications.

[if-cf-def "discounted-price" "discount-expires" logic="and"]
    This product is on discount, get it now for [cf "discounted-price" /] [cf "discount-expires" default="for a limited time"]before %value%


Please note: It seems that there is a serious bug in WordPress’ shortcode parser that prevents shortcodes from functioning correctly in certain occasions. The developers are hard at work to get this fixed before the 2.8.3 release. (See #10082) Therefore, please do not report any parser related bugs for the moment. (e.g. the shortcode is displayed on the actual page)


  1. Extract the zip file and drop the contents in the wp-content/plugins/ directory of your WordPress installation
  2. Activate the Plugin from Plugins page


ह्या प्लगइनसाठी कोणतेही समीक्षण नाही.

योगदानकर्ते आणि विकसक

“Conditional Custom Fields Shortcode” हे मुक्त स्रोत सॉफ्टवेअर आहे. पुढील लोक या प्लगइनच्या निर्मितीत योगदान केले आहे.


भाषांतर करा “Conditional Custom Fields Shortcode” तुमच्या भाषेत.

विकासातील आग्रह?

कोड ब्राउझ करा, SVN संग्रहालय तपासा, किंवा विकास लॉग च्या RSS द्वारे सदस्यता घ्या.