1

I use this construction to implement my own shortcode:

function column_with_icon($atts, $content = null) {
    extract(shortcode_atts(array(
        'icon' => 'onebit_03'
    ), $atts));

    return '<div class="column3">
    <img class="features-icon" alt="icon" src="' . get_bloginfo("template_url") . '/images/icons/' . $icon . '.png"/>
                            <div class="feature-content">' . $content . $icon . '</div>';
}

add_shortcode('column-icon', 'column_with_icon');

When I try to add a content like this:

[column-icon icon="onebit_13"]
<h3>What is Lorem ipsum?</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
<a href="#" class="main-theme-link">Learn more</a></div>
[/column-icon]

The default value of 'icon' attribute is not overridden and I get it equal 'onebit_03', not 'onebit_13' What can I do about this?

UPDATE Here is the code I use to retrieve and present the data:

function skible_load_special_offer_section() {
    $content = get_option("prc_speciall_offer_text", true);
    if (get_option("prc_show_special_offer_section")) {
        echo stripslashes(do_shortcode('<!--Start Special offer (in border) content-->
                    <div class="border-top"></div>
                    <div class="border-middle">
                        <div class="special-offer-area">
                            <div class="special-offer-image-left">
                                <img alt="image" src="' . get_bloginfo("template_url") . ' /colors/magic_night/special-offer-image.png"/>
                            </div>
                            <div class="special-offer-content-right">' . $content . '</div>
            <div class = "clear"></div>
            </div>
            </div>
            <div class = "border-bottom"></div>
            <!--End Special offer (in border) content-->'));
    }
}
4
  • I've copied your code for test and default attribute gets overridden correctly. Not sure what the issue is, but it isn't displayed by this code alone.
    – Rarst
    Oct 20, 2010 at 8:58
  • I forgot to say that I use this shortcode not in a normal post, but in my custom text field that I modify in admin console. May be it doesn't work because of that? I will try to dig deeper into the issue. I have just checked it in a normal post and it works well there. So, what can I do to make it work properly from a custom text field? Oct 20, 2010 at 9:28
  • You mean in Custom Fields meta box? How do you retrieve and display it?
    – Rarst
    Oct 20, 2010 at 10:22
  • No, I use programmatically created fields that I retrieve using get_option(). Please check the main question update to see the code. Oct 20, 2010 at 10:35

1 Answer 1

1

I have no idea what goes wrong at your setup. Clearly shortcode is properly registered, but some specific case something prevents it from being parsed correctly.

This is test code that roughly replicates how shortcode is parsed for execution :

$content = get_option("prc_speciall_offer_text", true);
$pattern = '/'.get_shortcode_regex().'/s';
preg_replace_callback( $pattern, 'var_dump', $content );

Array output should match following, according to get_shortcode_regex() spec:

1/6 - An extra [ or ] to allow for escaping shortcodes with double [[]]

2 - The shortcode name

3 - The shortcode argument list

4 - The self closing /

5 - The content of a shortcode when it wraps some content.

This is what it dumps for me:

array
  0 => string '[column-icon icon="onebit_13"]
<h3>What is Lorem ipsum?</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
<a href="#" class="main-theme-link">Learn more</a></div>
[/column-icon]' (length=389)
  1 => string '' (length=0)
  2 => string 'column-icon' (length=11)
  3 => string ' icon="onebit_13"' (length=17)
  4 => string '' (length=0)
  5 => string '
<h3>What is Lorem ipsum?</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
<a href="#" class="main-theme-link">Learn more</a></div>
' (length=345)
  6 => string '' (length=0)

Your Answer

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

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