If you want to display an XML fragment in a WordPress post - how do you do that?
Suppose you want to display this:
<family> <dad>whatever</dad> <mom>whatever</mom> </family>
Using the [sourcecode language="xml"]
does not help, as it mangles up the XML.
Also, I believe, plugins cannot be used with free version of WordPress ( i.e wordpress.com ) - so, probably that won't be an option.
Using HTML <pre>
tag works, but it does not give correct look and feel.
Can any one show me how they have done it?
The wordpress codex has a whole page about writing code in your posts.
http://codex.wordpress.org/Writing_Code_in_Your_Posts
Their suggestion is to use html entity codes within <pre>
or <code>
tags
<family>
<dad>whatever</dad>
<mom>whatever</mom>
</family>
This could be tedious if you have a lot of code to show in your post. I suggest writing a small shortcode that would do this for you.
<?php
function xml_shortcode( $atts, $content ) {
return '<pre>' . htmlentities( $content ) . '</pre>';
}
add_shortcode( 'xml', `xml_shortcode` );
?>
How to use your shortcode in a post
[xml]your code here[/xml]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With