• I’m finally making the move to Gutenberg and would like to know if there is a hook I can use to target just non Gutenberg posts? I have a lot of posts (from back to 2008!), some of which require a JavaScript code highlighter.

    I don’t need this on new, Gutenberg created posts though. Is there a filter to target just non Gutenberg posts so I can add that JS file just to those posts that need it?

Viewing 1 replies (of 1 total)
  • By default, posts aren’t stored with metadata that indicates which editor was used for them.

    One option is use something like has_blocks (https://developer.www.ads-software.com/reference/functions/has_blocks/) to check if the post content has any blocks, and if not, enqueue your JS.

    But it depends on your specific case, as things get kind of muddy with Classic Editor blocks and if you intend to have any “mixed” content, etc.

    What I would likely do instead is figure out what markup would exist in a post that means it needs the code highlighter javascript code. If the post contains that, enqueue the JS.

Viewing 1 replies (of 1 total)
  • The topic ‘Hook to add js file just for posts created with classic editor?’ is closed to new replies.