visual editor - How do I prevent Wordpress from eating my code?

I'm writing a guide and putting code examples. If I use the visual editor the code indentation is lost. It will als

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745465402a4628895.html

相关推荐

  • visual editor - How do I prevent Wordpress from eating my code?

    I'm writing a guide and putting code examples. If I use the visual editor the code indentation is lost. It will als

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信