0

I'm writing a guide and putting code examples. If I use the visual editor the code indentation is lost. It will also take some code and strip it out. If I use the text editor I can't ever switch to the visual editor again or the formatting and markup is lost.

This doesn't happen in other editors like Discourse.

I'm using Geishi syntax highligher.

Is there anyway to prevent this?

  • Is using Gutenberg an option for you? If yes you could use the Preformatted block to easily solve your problem. gogutenberg.com/blocks/preformatted – filipecsweb May 25 '19 at 3:00
  • I don't know if I can switch to the gutenberg editor. – 1.21 gigawatts May 25 '19 at 3:16
  • You said some code is being stripped... are you editing/saving the post as an administrator? And can you post your post content here? – filipecsweb May 25 '19 at 3:27
  • The code is not meant to be interpreted or parsed. It's meant to be example code to be included visibly in the post. – 1.21 gigawatts May 25 '19 at 3:48
0

If you look at the editing box, you'll see the curly braces as a choice. Highlight your code block, then use that curly braces icon. That will wrap the code in a 'code' block, so it will look like this:

<?php 
   // this is a code block
   echo "this is a code block";

You can do the same in text mode (rather than visual) by using the HTML 'code' tag.

| improve this answer | |
  • I don't see any curly braces. In the text mode I use the code tag and that wraps it in code tags but when I switch to the visual view the code indentation is collapsed. – 1.21 gigawatts May 25 '19 at 5:38
  • Try the dropdown for the heading/paragrap thing. There is a 'preformatted choice that should work. I may see the curly bracket thing because of a plugin or customization I had done, or it could be a theme thing. – Rick Hellewell May 25 '19 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.