Support » Plugins » Hacks » PHP code in Post, problem

  • Resolved macrunner

    (@macrunner)


    Hi,
    if I enter the following code in an article, (using the pre or code tags):

    if( !empty( $testx ) ) {
    
    $output = apply_filters( 'test_name_output', sprintf( '<h2 class="testx">%s</h2>', $testx ) );
    
    echo $output;

    part of this code is “converted” and I get the following result, screenshot: http://i.imgur.com/13uXZUt.png

    This problem occurs with any theme.
    Tried with WordPress 4.4.xx AND 4.5.xx, same problem

    Thanks for any help or suggestions.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The WP visual editor tries to correct invalidly nested markup and is getting thrown off by the <h2> and </h2> tags in your code.

    Try converting these to HTML entities first.

    Edit: hilariously, the editor here is converting my HTML entities into actual HTML.

    Replace the < with & lt; (remove space) and the > with & gt; (remove space).

    Thread Starter macrunner

    (@macrunner)

    Thanks karpstrucking, works great!

    🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP code in Post, problem’ is closed to new replies.