Home Forums ACF PRO ACF Blocks: how to apply backend styles different from the frontend ones?


ACF Blocks: how to apply backend styles different from the frontend ones?

  • Hi, I’m building my first ACF blocks. The acf_register_block_type() lets you add an ‘enqueue_style’ option, but the styles are applied both to frontend and backend, and that’s not what I want.

    I can add only forntend styles simply adding them to my regular style files, without using acf_register_block_type. Good.

    But how can I add only-admin styles? Is there a way?

    Thank you

  • I can answer by myself.

    To load styles only for backend, you can use the enqueue_block_editor_assets action:

    function add_block_editor_assets(){
      wp_enqueue_style('block_editor_css', [yourpath] . '/editor-blocks.css');
    • city17

    • September 9, 2019 at 5:37 pm

    This was exactly what I was looking for, had the same question. Just one thing: Your method has as a downside that it now loads on every post editor, even if the specific block for which the style or script is is not used.

    Is there a way to make it conditional on a specific custom ACF block being used?

    • stratboy

    • September 12, 2019 at 4:07 pm

    Mmm I don’t know: developers here could give some help 🙂 Toc toc? Hey there! 🙂

    • rom_uht

    • January 6, 2020 at 10:09 pm

    Don’t you get Cannot modify header information warning with this function ??

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.