admin管理员组

文章数量:1431426

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?

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?

Share Improve this question edited May 25, 2019 at 12:21 fuxia 107k39 gold badges255 silver badges459 bronze badges asked May 25, 2019 at 2:55 1.21 gigawatts1.21 gigawatts 1,0003 gold badges13 silver badges34 bronze badges 4
  • Is using Gutenberg an option for you? If yes you could use the Preformatted block to easily solve your problem. gogutenberg/blocks/preformatted – filipecsweb Commented May 25, 2019 at 3:00
  • I don't know if I can switch to the gutenberg editor. – 1.21 gigawatts Commented May 25, 2019 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 Commented May 25, 2019 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 Commented May 25, 2019 at 3:48
Add a comment  | 

1 Answer 1

Reset to default 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.

本文标签: visual editorHow do I prevent Wordpress from eating my code