Yesterday, after a week of working, polishing, and dithering, I published my first â€œhow-toâ€ post. Yay me.
I was really happy to find a plugin called SyntaxHighlighter Evolved to make my code stand out from the supporting text. It allows me to copy my source code into the post editor and preserve things like spacing while also highlighting different language elements.
They say you should always include an image in a post, to help draw reader attention, alleviate the boredom of unbroken text, and so on. The only image Iâ€™d included was a screenshot of how the example plugin looks on the Dashboard -> Plugins page, so when I published a link to the new post on Facebook, that was the image that was used. Not terribly effective, and certainly not artistic. How could I make this better?
Rather than search for some stock image that might somehow be related to my post, I decided to take a screenshot of the code as displayed by SyntaxHighlighter. Nice and colorful, and certainly related to the post content. To make it more â€œartisticâ€ I rotated and cropped it. That looked good.
Next came the fiddling.
First time around I simply inserted the image at the top of the post. It looked ok, but not great, stuck between the headline and the text. I suppose I could live with it, but to have it included as the image in social media links I should make it a featured image. (Thereâ€™s a spot on the post editing page for doing that.)
Adding a featured image doesnâ€™t always do anything for how the post looks on the website â€” it depends on the theme youâ€™re using. Some themes use it for the header image, some display it only in lists of posts, some donâ€™t use it at all. Iâ€™m currently using WordPressâ€™ Twenty Thirteen theme, for the first time, so I wasnâ€™t sure what would happen.
I pushed the Update button and then viewed the page to see what happened.
The image was there twice â€” once above the headline, and once below.
I went to the main page (which lists the most recent posts) and saw the image twice. This wouldnâ€™t do.
I went back and edited the page again, leaving the â€œfeatured imageâ€ but deleting it from where Iâ€™d placed it in the post content. Update and check again.
This time things looked good. On the home page the featured image was placed above the headline, which was next to the start of the page content. Checking the post page revealed the same thing.
All of my code extracts had been trashed. They were still there, but squished into a single line. What the heck?
I went back to the post editor, again, and switched it from â€œvisualâ€ to â€œtextâ€ mode. Visual mode is generally more comfortable for people because what they see is closer to what things look like when published. Bold text looks bold, italics looks italicized, etc.
Text mode shows you more of the underlying HTML tags that implement that bold and italic text. It still doesnâ€™t show everything, however. Paragraph and line breaks, in particular, are sometimes hidden so that you donâ€™t have to worry about whether or not theyâ€™re properly closed. WordPress takes care of that when the post is saved.
Unfortunately, in the process of saving, closing, and reediting, the new-line characters in my code samples had become converted into line break tags (<br />) which SyntaxHighlighter then interpreted as part of the code. Since there were no remaining new-line characters, the code was compressed into a single line.
In every single snippet. Grrr.
I wound up learning a lesson: Add the code snippets last, after everything else is polished to perfection. And do it in Text mode. Then preview and save, and donâ€™t fiddle with it once itâ€™s published.