Plugin này chưa được cập nhật với 3 phiên bản mới nhất của WordPress. Nó có thể không được hỗ trợ và bảo trì, và có thể xung đột với các phiên bản WordPress mới nhất.

If Shortcode

Mô tả

This plugin provides an “if” shortcode to conditionally render content. The syntax is the following:

[if condition1 condition2=false condition3]{content}[/if]

Conditions are passed as attribute names. Multiple conditions evaluate to the result of ORing all of them. In other words,
if at least one condition evaluates to the desired boolean result, {content} is rendered, otherwise it is discarded.
Attribute values determine if we want the condition to be true or false. A value of ‘0’, ‘false’, ” (the empty string),
‘null’ or ‘no’ means we expect the condition to be false. Anything else, including the absense of a value, is interpreted
as true.

For example, suppose that we want to include a sentence in a post, but only for anonymous visitors:

[if is_user_logged_in=no]The Sentence.[/if]

It also provides an [else] shortcode and an [eitherway] one for use inside [if] blocks. [else] will render its content if
the condition evaluates to false, and [eitherway] will render its content regardless of the evaluation result. When used
outside an [if] block, these shortcodes behave as if the whole content is surrounded by an [if] shortcode whose condition
evaluates to true. In other words, an [else] shortcode would not render any content, while a [eitherway] one would. You can
use as many of these shortcodes as you like in a single [if] block, which gives you the ability to do things like:

    - Am I logged in?
    [if is_user_logged_in]- Yes you are.
    [else]- No you are not.
    [/else][eitherway]- I'm sorry, what?
    [/eitherway]- I said YOU A-R-E LOGGED IN!!!
    [else]- YOU ARE NOT LOGGED IN!!! What's the matter with you?[/else][/if]

A multitude of conditions are supported out-of-the-box. The following evaluate to the result of the corresponding
WordPress Conditional Tag, using the no-parameter syntax:


For example, the evaluation of the is_page condition is equivalent to calling is_page() with no parameter.

The functionality of the plugin can be extended by other plugins, by means of adding custom conditions through filters.
To add a custom condition, a filter hook must be defined in the following manner:


function my_condition_evaluator($value)
    $evaluate=.... /* add your evaluation code here */
    return $evaluate;

A big thanks to M Miller for the normalize_empty_atts() function found here:

Cài đặt

Install the plugin using the usual method described in the codex.

Đánh giá

23 Tháng Mười Hai, 2016
I needed to show a login form only to people not logged in. This little plugin was perfect! Now I'm getting all kinds of ideas for what I can do with it. Thanks!
3 Tháng Chín, 2016
If you are wanting to hide or show links or text based upon logged in state, author or quite a few other "is" conditions this plugin is perfect. Thanks G J
Đọc tất cả 7 đánh giá

Người đóng góp & Lập trình viên

“If Shortcode” là mã nguồn mở. Những người sau đã đóng góp vào plugin này.

Những người đóng góp

Nhật ký thay đổi



  • Addition: [else] shortcode
  • Addition: [eitherway] shortcode


  • First release.