Title: PHP code in Post, problem
Last modified: September 1, 2016

---

# PHP code in Post, problem

 *  Resolved [macrunner](https://wordpress.org/support/users/macrunner/)
 * (@macrunner)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/php-code-in-post-problem/)
 * 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](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)

 *  [Lucas Karpiuk](https://wordpress.org/support/users/karpstrucking/)
 * (@karpstrucking)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/php-code-in-post-problem/#post-7467901)
 * 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](https://wordpress.org/support/users/macrunner/)
 * (@macrunner)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/php-code-in-post-problem/#post-7467943)
 * 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.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 2 participants
 * Last reply from: [macrunner](https://wordpress.org/support/users/macrunner/)
 * Last activity: [9 years, 11 months ago](https://wordpress.org/support/topic/php-code-in-post-problem/#post-7467943)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
