WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Bug short codes add double quotes at the end (5 posts)

  1. atlanteavila
    Member
    Posted 1 year ago #

    Hi all please help! This is driving me nuts!

    I have a shortcode that I'm trying to add to my theme:

    this is the shortcode:

    function one_half( $atts, $content = null ) {
    	return "<div class='eight columns'>" . $content . "</div>";
    }
    
    add_shortcode('one_half', 'one_half');

    This is what it outputs:

    <div class="eight columns">Half columns</div>&nbsp;<div class="eight columns">Half Second columns</div>

    Not sure if you can see it here but when I look up my source, I see this exactly:

    <div class="eight columns">Half columns</div>" "<div class="eight columns">Half Second columns</div>

    and the "" make it break. Is there anything I'm missing? Please help!

    Thanks!

    P.S. I have already tried to put the following php code to remove the p tag which helped but didn't remove the "":

    remove_filter ('the_content', 'wpautop');

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Try:

    function one_half( $atts, $content = null ) {
    	return '<div class="eight columns">' . $content . '</div>';
    }
    
    add_shortcode('one_half', 'one_half');
  3. atlanteavila
    Member
    Posted 1 year ago #

    Thanks esmi, tried that before posting this and still the double quotes show up, but what I realized is that they show up because of the space I would put on there would create a &nbsp; I removed any spaces between the shortcodes and added a line break and the problem went away. That was so weird!

  4. Mr. Vibe
    Member
    Posted 1 year ago #

    same issue here as well.
    If you have a shortcode which accepts parameters as :

    [tooltip tip="Some tooltipc ontent here "]Tooltip Anchor[/tooltip]

    now if I call this tooltip manually at some place using:

    $string='[tooltip tip="Some tooltip content here "]Tooltip Anchor[/tooltip]';
    echo do_shortcode($string);

    You'll see that top ends at "Some" , breaks at space...
    Weird, I guess that is a bug.

  5. Mr. Vibe
    Member
    Posted 1 year ago #

    Update: I found that my issue isn't exactly the same as this one. As I was first storing the shortcode in the database postmeta and then outputting the shotcode. While saving in post meta the shortcodes double quotes & single quotes got converted in hex code which were not recognized by the do_shortcode on execution which resulted in this behaviour of shortcodes.

    ( v )

Topic Closed

This topic has been closed to new replies.

About this Topic