Title: Displaying PHP-Code in a post
Last modified: August 18, 2016

---

# Displaying PHP-Code in a post

 *  [Jérôme](https://wordpress.org/support/users/jerome/)
 * (@jerome)
 * [22 years, 8 months ago](https://wordpress.org/support/topic/displaying-php-code-in-a-post/)
 * Hi!
    I came to WordPress only yesterday, and I am **really** impressed – and 
   so, I am using it right now ;). I want to make a sort of a development blog while
   programming my own (simple) scripts. As I want to show the progress to the visitors,
   it would be great if I could display colored PHP-Code in my posts. Do you perhaps
   know a way to do this? Thank you very much in advance – Jérôme

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

 *  Thread Starter [Jérôme](https://wordpress.org/support/users/jerome/)
 * (@jerome)
 * [22 years, 8 months ago](https://wordpress.org/support/topic/displaying-php-code-in-a-post/#post-24840)
 * Okay :o), if nobody wants to help me, I will try to get into WordPress and do
   it on my own. But don’t blame me, if my blog crashes ;).
 *  [alexkingorg](https://wordpress.org/support/users/alexkingorg/)
 * (@alexkingorg)
 * [22 years, 8 months ago](https://wordpress.org/support/topic/displaying-php-code-in-a-post/#post-24841)
 * I think I’ve seen some JavaScripts that will do this… can’t remember where though.
 *  [Dougal Campbell](https://wordpress.org/support/users/dougal/)
 * (@dougal)
 * [22 years, 8 months ago](https://wordpress.org/support/topic/displaying-php-code-in-a-post/#post-24848)
 * Jerome, colorizing PHP code inside an HTML post is a non-trivial task.
    It would
   be _far_ easier if you put your code in separate files with a ‘.phps’ extension(
   if your server supports that), and link to those. If you want to get fancy, store
   the code in external files, then put an <iframe src=”myfile.phps” /> in your 
   post.
 *  [Dougal Campbell](https://wordpress.org/support/users/dougal/)
 * (@dougal)
 * [22 years, 8 months ago](https://wordpress.org/support/topic/displaying-php-code-in-a-post/#post-24863)
 * Actually, we’re currently using XHTML 1.0 Transitional, and iframe is valid there.
   
   About the only other way I can think of to do it would be to bring up the .phps
   file in your browser, view source, then cut-n-paste that source into your WordPress
   posting. Of course, the PHP source coloring code uses the font tag, so if you’re
   concerned about maintaining xhtml validity, that’s out, too 🙂
 *  [Mike Little](https://wordpress.org/support/users/mikelittle/)
 * (@mikelittle)
 * [22 years, 8 months ago](https://wordpress.org/support/topic/displaying-php-code-in-a-post/#post-24869)
 * Hi Jerome,
    it is *much* simpler than that. simply call highlight_file(‘your_file_name.
   php’) which will echo the syntax highlighted source code from the file in place.
   There is a second optional boolean parameter which forces it to return a string
   rather than echo. Of course Dougal’s point about font tags is still valid (or
   rather invalid for xhtml transitional) Hope this helps, Mike
 *  Moderator [Matt Mullenweg](https://wordpress.org/support/users/matt/)
 * (@matt)
 * [22 years, 8 months ago](https://wordpress.org/support/topic/displaying-php-code-in-a-post/#post-24872)
 * I’ve been meaning to write something to highlight code in a XHTML/CSS fashion,
   and I saw in the latest php|architect they have a script that does just that.
   Great minds…
 *  [Dougal Campbell](https://wordpress.org/support/users/dougal/)
 * (@dougal)
 * [22 years, 8 months ago](https://wordpress.org/support/topic/displaying-php-code-in-a-post/#post-24886)
 * Ha, I forgot all about there being a highlight_file() function. Duh 🙂
    Um…. 
   But getting a PHP function call into the middle of a blog post is another matter….
   Which is the same reason that I almost suggested (but did not, because my test
   didn’t work) using [?php include(‘[http://mysite/myfile.phps&#8217](http://mysite/myfile.phps&#8217););?]
   So I’m thinking that the iframe is still going to be your best bet for right 
   now. It will work, and your main page will still validate.

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

The topic ‘Displaying PHP-Code in a post’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 5 participants
 * Last reply from: [Dougal Campbell](https://wordpress.org/support/users/dougal/)
 * Last activity: [22 years, 8 months ago](https://wordpress.org/support/topic/displaying-php-code-in-a-post/#post-24886)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
