0

I am trying to insert PHP code in post content, but I've just realized that it brokes Wordpress or maybe some plugin.

As for example

avoid any specific class naming structure or style.
<?php 

You can see this simple example at work in this CodePen demo. Resize the window to see the change take place.

So in this case You can see ... won't be rendered as output.

If php tag is closed like this

  avoid any specific class naming structure or style.
    <?php 
    // Some code 
    ?>

    You can see this simple example at work in this CodePen demo. Resize the window to see the change take place.

I this case everything work just fine...

I also tried to wrap using pre,cod and shortcodes, but still the same.

I am using the latest version of wordpress. Maybe someone has already faced with this problem.

Thanks.

  • What is the goal of <?php \\Some code ?>? If simply to show the markup, wrapping it in a <code> tag should work (depending on your plugins and theme). If you wish to execute the PHP code, it will not ever work without breaking WP. – Nathan Powell Nov 19 '16 at 5:40
  • Doesn't work. It is doing something weird, I have no idea what happens. – gzbuaapzroyn Nov 19 '16 at 7:55
  • What doesn't work? – Nathan Powell Nov 19 '16 at 7:57
  • Even code,pre .. as I've described in my question. I don't wish to execute code, it is executed automatically or whatever is happened – gzbuaapzroyn Nov 19 '16 at 8:36
0

If you only want the php code to be output without executing it, just escape the < signs by replacing it with the html entity &lt;.

&lt;?php

Like this, the tag will not be recognised and will be output as <?php.

  • This is already done here is formatted code example <span class="cp">&lt;?php</span> – gzbuaapzroyn Nov 19 '16 at 12:26
  • @gzbuaapzroyn Please clarify your question, describing how you are inserting the code into post content and showing the code you use to achieve that. Just showing what you are inserting, leaving away that it already is being escaped, makes us have to do wild guessing – JHoffmann Nov 19 '16 at 14:22

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.