5

I want to write some python code in a wordpress blog but whitespaces are not preserved. Can some one please tell me how to write my python code in the blog with the proper indentation and styling preserved as indentation is very important for python code.

manyu
  • 475
  • 2
  • 6
  • 12
  • 1
    Have you tried using `pre` or `code` tags? – Jon Clements Jul 10 '12 at 12:21
  • yes i have but...how to style code as it is shown by the editor... – manyu Jul 10 '12 at 12:26
  • 1
    If you mean highlighting? Then it's a plugin... Otherwise, just make sure it's space indented – Jon Clements Jul 10 '12 at 12:28
  • @JonClements found solution, there are [sourcecode language="python"] tag in wordpress it self and to maintain the indentation as well you just need to paste the code into the html not in the visual tab....worked for me... – manyu Jul 11 '12 at 10:24
  • Oh awesome - thanks for letting me know - always good to learn something new :) – Jon Clements Jul 11 '12 at 11:43
  • It is very late to add this, but if you mean a blog on wordpress.com, there is a great post about it at http://pythonconquerstheuniverse.wordpress.com/2011/11/06/posting-sourcecode-on-wordpress/ – TimothyAWiseman Dec 21 '12 at 01:42

1 Answers1

7

Use html <code> tag.

You can also try this very good plugin for code highlighting in WP.

WP-SynHighlight

And for blog hosted on wordpress.com:

As perfect answer on this stack post.

Community
  • 1
  • 1
Rikesh
  • 26,156
  • 14
  • 79
  • 87
  • I really don't knw how to use the pluggins tried installing the wordpress but cudn't link my present wordpress account with it. It seems that after installing the wordpress on your machine it treat it as a new account .....i really don't have idea how to go around it – manyu Jul 10 '12 at 12:29
  • You don't have to install all new wordpress for plugin..it just a option in your admin backend.. and there you can add new plugin after searching it. – Rikesh Jul 10 '12 at 12:31
  • how to link my present account with it ? – manyu Jul 10 '12 at 12:32
  • 1
    @manyu if your blog is hosted on `wordpress.com` than sorry you can't install any plugin over there. you can only do using `` tag. – Rikesh Jul 10 '12 at 12:37
  • hmm thats what I realised after installing wordpress on my machine ....going to use tag only.... is there a way to style my code as it is shown in the editor ?? – manyu Jul 10 '12 at 12:39
  • 1
    No. To style your code you need to install plugin. – Rikesh Jul 10 '12 at 12:40
  • 1
    found solution, there are [sourcecode language="python"] tag in wordpress it self and to maintain the indentation as well you just need to paste the code into the html not in the visual tab....worked for me... – manyu Jul 11 '12 at 10:24
  • Great !! Updated my answer so that helps other .. – Rikesh Jul 11 '12 at 10:32