In Oxygen Slack, a user asks:

is there a way to “comment out a section in oxygenbuilder?

Setting display to none for a Section will not show it both in the Oxygen editor as well as the frontend. But a bigger issue is that all its actual HTML itself will still be output on the frontend.

We can use the recently added Shortcode Wrapper element and wrap Sections that should be “commented out” or “unpublished” in a custom shortcode that will simply not return anything thereby not outputting the Section on the frontend at all.

Step 1

Install and activate Code Snippets plugin.

Step 2

Go to Snippets > Add New.

Title: Shortcode to not output elements

Code:

add_shortcode( 'isempty', 'dont_output_this_element' );
function dont_output_this_element( $atts, $content = '' ) {
    return "";
}

Set it to run everywhere.

Step 3

In the Oxygen’s editor, open the Structure panel and select the Inner Content (or the top-most item) and add a Shortcode Wrapper (+ Add > WordPress).

Drag your Section that you wish to not show on the frontend inside the Shortcode Wrapper.

Select the Shortcode Wrapper and paste the following for the Full shortcode:

[isempty][/isempty]

That’s it!

This Section will now not be output on the frontend.

Note that empty markup similar to

<div id="nestable_shortcode-7-2" class="ct-nestable-shortcode"></div>

will be left behind in the frontend.

I have created a topic in the Feature Requests forum asking them to fix this here.

When you are ready to uncomment and “publish” your Section again, move it back to where it was out of the Shortcode Wrapper.

Reference: https://codex.wordpress.org/Shortcode_API#Enclosing_vs_self-closing_shortcodes

Need help implementing a tutorial in your site or want to hire me for custom work?

HIRE ME

Find the article helpful and wish to donate?

DONATE

Comments

For adding code blocks wrap the code in three backticks. Markdown should work.
Provide a URL of your site/webpage if something is not working.
  • Brilliant. Can this be used responsively? Remove code dependant on screen size?
    Apologies, I posted this qustion on How to unpublish Oxygen Sections for specific user roles by mistake!

  • >
    linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
    %d bloggers like this: