0

I'm using short codes of my own and I realised that it strips some html code away and messes up with what I wrote in my code.

Let's start with an example.

In Wordpress I add [myshortcode id="99"]

In PHP I have:

function myshortcode($atts)
  {
      $my_id = $atts["id"];
      ob_start();
      echo "<div>".$my_id."</div>";
      $content = ob_get_contents();
      ob_end_clean();
      file_put_contents("log.txt",$content);
      return $content;
  }

add_shortcode( 'myshortcode', 'myshortcode' );

In my log file (log.txt), I find this:

<div>99</div>

In my rendered page, I find this:

99

It looks like Wordpress is doing something with the output of my short code and stripping away my DIV. Links are working but html tags aren't. I also see sometimes
tags being added while it doesn't make sense.

Is there a way to prevent WP from doing this ?

Thanks

Laurent

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.