• Hello all,

    I’m having trouble outputting some html from a WordPress shortcode. It removes some of the code but not everything.

    
    function sound_intro($atts)
        {
          ob_start();
         ?>
         <select on="change:AMP.setState({ activeDiv: event.value })">
         <option value=0></option>
         <option value=1>Div 1</option>
         <option value=2>Div 2</option>
         </select>
         <div hidden [hidden]="activeDiv != 1">Div 1</div>
         <div hidden [hidden]="activeDiv != 2">Div 2</div>
       <?PHP
      $contents = ob_get_contents();
      file_put_contents("<somewhere>",$contents,FILE_APPEND);
      ob_end_clean();
    return $contents;
    }
    add_shortcode( 'sound_intro', 'sound_intro' );
    

    This code results in the following code in my browser:

    
    <select on="change:AMP.setState({ activeDiv: event.value })">
    <option value="0"></option>
    <option value="1">Div 1</option>
    <option value="2">Div 2</option>
    </select>
    </p>
    <div hidden>Div 1</div>
    <div hidden>Div 2</div>
    

    So as you can see some html is missing and it breaks the logic of what I want to achieve.

    I’m storing the html in a text file before outputting the results and in this file, the html is perfectly preserved. This would mean that between the “return” and the actual display, WordPress is stripping some code away.

    do you have any idea of what is happening?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • The part that is missing is not valid HTML or valid PHP or valid javascript. Which is it supposed to be?
    I would suspect that somewhere there is a filter, and I would suspect AMP first.

    Thread Starter klintistwoood

    (@klintistwoood)

    Hello Joy,

    Thanks!
    I know it doesn’t look standard but it’s made for AMP so it should work. I have copied exactly the same HTML directly into my code (not using a short code) and in this case, the html is not altered. It’s only when I use a short code that some form of cleaning appears.

    Thanks

    Moderator bcworkz

    (@bcworkz)

    I put your shortcode code into my teat site and entered [sound_intro] into post content. The HTML came through on post output exactly as defined in the shortcode handler, nothing was stripped out. So whatever is happening to your content is not due to some standard WP filtering.

    Since the same HTML without going through shortcodes also comes through intact, it doesn’t leave us with many places where the HTML could become corrupted. What is supposed to happen with [hidden]? Just another shortcode? If so, it seems the processing of this shortcode is messed up to the point where not only does it not replace the shortcode with content, it takes out an extra chunk of HTML in the process.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Shortcodes remove some html’ is closed to new replies.