• Anonymous User 7536166

    (@anonymized-7536166)


    Hi,

    Using the codex example
    [gallery id="123" size="medium"]

    I can’t get the following to work…

    [gallery
        id="123"
        size="medium"
    ]

    If I have everything on one line my code works great, split it up for easy reading, and it stops working.
    Is there any way of fixing this, or is it a ‘bug’?

    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • I believe what’s happening is a post filter is interpreting what you’ve written as regular text and is applying the filter that converts line breaks to <br/> tags… I’m afraid I don’t know the solution, but maybe that will point you in the right direction?

    Thread Starter Anonymous User 7536166

    (@anonymized-7536166)

    Thanks datdesignguy.
    Doing some more testing, it looks like something is also stripping the /> part off the <br />. It is rather annoying.

    hmmm… have you tried examining what filters are being applied to see if there is anything out of the ordinary going on? I am trying to figure out what function it is that allows you to inspect action hooks to display the filters currently being applied. It might be possible that another plugin is incorrectly interfering with your shortcodes… IDK.

    I believe if you do a print_r($wp_filters[‘the_content’]) it’ll show you what filters are being applied and their priorities, you can look up those filters in the codex to see if any of them could be causing the stripping problem you mentioned.

    well it’s shortcode, not code. the difference being it’s not designed for formatting. it’s designed to be in a short block.

    not saying you can’t change that, just saying it’s not a bug, it’s supposed to be that way. (i believe)

    changing the filters should do it.

    Thread Starter Anonymous User 7536166

    (@anonymized-7536166)

    I added print_r($wp_filters[‘the_content’]) to the top of the shortcode function, but nothing is being shown. I even added echo "---"; before and after the line, and they show up fine.

    I did have my section of code working fine when I was using $content = preg_replace_callback( "/(<$allblocks(.*?)>)?\[shortcode:([^]]+)](<\/$allblocks>)?/i", "shortcode_func" , $content); but then I found that using add_shortcode is a much better way.

    Thread Starter Anonymous User 7536166

    (@anonymized-7536166)

    OK, got some output…

    This was from print_r($atts);, so basically everything I am passing to the shortcode…

    [shortcode
        title="default"
        desc="true"
        aps="false"
        images="North America/Seattle/Duck Tour/IMG_1_0141.jpg,
            North America/Coeur D'Alene/IMG_1_0275.jpg,
            "
    ]

    Array
    (
        [0] =>
     />
        [2] => title="default"
     />
        [4] => desc="true"
     />
        [6] => aps="false"
     />
        [8] => images="North
        [9] => America/Seattle/Duck
        [10] => Tour/IMG_1_0141.jpg,
     />
        [12] => North
        [13] => America/Coeur
        [14] => D'Alene/IMG_1_0275.jpg,
     />
        [16] => "
     />
    )

    Thread Starter Anonymous User 7536166

    (@anonymized-7536166)

    Ok, I have hacked some code together that fudges the array. It’s currently working for me…

    Add this at the top of the shortcode function, before extract(shortcode_atts(array(....

    $atts = array_reduce($atts,"join_array");            // Join array into one string
    $atts = trim(str_replace('<br />', ' ', $atts));     // Replace '<br />' with ' ' (space)
    $atts = explode('" ', $atts);                        // Split into array
    
    $_atts = array('0'=>'0');                            // Create empty array
    foreach ($atts as $keyvaluepair)
    {
        $tmp1 = explode('=', $keyvaluepair);
        $tmp2 = array(trim($tmp1[0]) => trim(str_replace('"', '', $tmp1[1])));
        $_atts = array_merge($_atts, $_tmp2);
    }

    As I said, it’s a fudge, but it works.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Multi-line shortcode’ is closed to new replies.