admin管理员组

文章数量:1122846

Is it possible to "comment out" a block in wordpress when using the block editor?

I'm working on a wordpress site, and I want to temporarily make some of the wordpress blocks invisible to site visitors, but remain intact in the visual block editor, such that it could be easily toggled to be visible again.

I am a developer, so ordinarily I would just operate in the classic code editor. For example, if I had a paragraph:

<p>hello world</p>

Then I could simply "comment it out" as follows

<!-- temporarily disabled in 2024 for reasons -maltfield
<p>hello world</p>
-->

However, I'm designing this site for an organization that doesn't have any developers on-staff, so I want to do the equivalent of the above, but such that the block can be made visible/invisible entirely only using the visual block editor.

Is it possible to toggle the visibility of a wordpress block using only the visual block editor?

Is it possible to "comment out" a block in wordpress when using the block editor?

I'm working on a wordpress site, and I want to temporarily make some of the wordpress blocks invisible to site visitors, but remain intact in the visual block editor, such that it could be easily toggled to be visible again.

I am a developer, so ordinarily I would just operate in the classic code editor. For example, if I had a paragraph:

<p>hello world</p>

Then I could simply "comment it out" as follows

<!-- temporarily disabled in 2024 for reasons -maltfield
<p>hello world</p>
-->

However, I'm designing this site for an organization that doesn't have any developers on-staff, so I want to do the equivalent of the above, but such that the block can be made visible/invisible entirely only using the visual block editor.

Is it possible to toggle the visibility of a wordpress block using only the visual block editor?

Share Improve this question asked Aug 18, 2024 at 16:50 Michael AltfieldMichael Altfield 18015 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 3

If you have a "hidden" CSS class in your theme that hide blocks (like .hidden {display: none}, you can add this class to your block in the editor using the "Advanced > Additional CSS class" control

  1. In the Block Editor, select the block you want to hide.
  2. Go to the "Advanced" section in the Block settings sidebar.
  3. Add a custom CSS class, like "hidden-block", to the "Additional CSS Class" field.
  4. Go to Tools > Theme File Editor from the wp-admin navigation.
  5. Add following style to the theme Stylesheet (style.css) and update.
body:not(.wp-admin) .hidden-block {
    display: none;
}

本文标签: How to quotcomment outquot a block in Wordpress (make it invisible without deleting it)