NOTE
I don’t want the php code to be executed, only displayed.
I want to display this php code <?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?>
inside a post. I cannot make it work.
If I go to text type of editor and type <pre class="lang:php nums:false"> <?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?> </pre>
there and save. I can see what I want to.
But when I switch to visual editor the php text is not there. There is box for it but the text is not there. If I save the post now html comments are added to the source code and it looks like <pre class="lang:php nums:false"> <!--?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?--></pre>
. So when I then refresh the post page I got !--
characters there, something that shouldn’t be there.
Any idea how to display php code with syntax highlight?
That may be a bit problematic. I use the plugin SyntaxHighlighter Evolved, but as the plugin description says (my emphasis):
Another option is to embed Gists (or similar) using a Shortcode to pass the URL and let PHP render the
script
tag (as suggested by Marco Berrocal).And the Shortcode path could also be used with Custom Fields. Paste the script in the CF and pass its name to the Shortcode for rendering. The plugin Advanced Custom Fields comes to mind.
If I were you, I would do a custom Shortcode, clean the PHP and display it on the way out.