logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$15
Shortcode Output Issue

Hi,
I'm using a modal window to add shortcodes into my posts. This part works fine, and adds the shortcode to the post like it's supposed to:

[message class=green-message]This is a message.[/message]


However, I'm having trouble getting this to output on the page properly. I have two other shortcodes built using the same method and they seem to work, however this one just won't output correctly.

This is the code I'm using to collect the shortcode info in a popup window: http://cl.ly/9RZE.

This is the code I'm using to output the shortcode on the page when published: http://cl.ly/9Q8N

I believe the issue is with this piece below (which is in the second link), but all the edits I've tried aren't working. It outputs the message but fails to output the class. Instead it display class=" ".


function message( $atts, $content = null )
{
extract( shortcode_atts( array(
'messcontent' => '',
'messtype' => '',
), $atts ) );

// convert the shortcode to this on the front end
return '<div class=" ' . $messtype . ' ">' . $content . '</div>';

}
add_shortcode('message', 'message');


Any help is appreciated!

This question has been answered.

Mike McAlister | 08/19/11 at 3:31am Edit


(3) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    08/19/11
    3:41am
    Utkarsh Kukreti says:

    function message( $atts, $content = null )
    {
    extract( shortcode_atts( array(
    'class' => '',
    ), $atts ) );

    // convert the shortcode to this on the front end
    return '<div class=" ' . $class . ' ">' . $content . '</div>';
    }

    add_shortcode('message', 'message');

  • avatar
    Last edited:
    08/19/11
    3:43am
    Nilesh shiragave says:


    function message( $atts, $content = null )

    {

    extract( shortcode_atts( array(

    'class' => '',

    'messtype' => '',

    ), $atts ) );



    // convert the shortcode to this on the front end

    return '<div class=" ' . $class . ' ">' . $content . '</div>';



    }

    add_shortcode('message', 'message');

  • avatar
    Last edited:
    08/19/11
    3:51am
    Julio Potier says:

    Hello

    You have to know how work a shortcode :

    a) When you call "[message class=green-message]This is a message.[/message]"
    b) "message" is the shortcode name, added by "add_shortcode( 'message' ...).
    c) "This is a message" is the "$content" var (default null).
    d) Also, "class=green-message" or "aaa=bbb" are attributes, it goes in the "atts" function in an array.
    e) The ligne "extract( ... )" will perform some action to convert the attributes in easy php var.
    so "class=green-message" will become "$class = 'green-message'", you can now use "$class" in your code.
    f) Then in a shortcut you have to "return" a value, never echoes it.

    In your actual code you wrote "[message class=green-message]This is a message.[/message]" Your shortcode does not use "$class" but "$messtype" !

    2 solutions :
    1. use this shortcode in place of the other.

    function message( $atts, $content = null )
    {
    extract( shortcode_atts( array(
    'class' => '',
    ), $atts ) );

    // convert the shortcode to this on the front end
    return '<div class=" ' . $class . ' ">' . $content . '</div>';
    }
    add_shortcode('message', 'message');


    2. or call
    [message messtype=green-message]This is a message.[/message]
    in place of your shortcode.

    See you !

This question has expired.



Mike McAlister voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.