• Hello community!

    I have one question that may be solved by someone here so I prefered to do this instead of opening an issue on GitHub. It concerns the new Widget Block Editor, introduced on WP 5.8.

    As a plugin developer, I use the has_block() function, to detect if a certain block is present in the current page, so I can decide if I have to load our javascript and css. This was working fine, but I noticed that it won’t do the job once footer and sidebar widgets areas are edited by the block editor.

    Is there any way for me to check if one of my blocks was inserted in a certain wdiget area, in a certain page, on time to at least unregister unecessary scripts and styles?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @wetah,

    String Locator is a good plugin for searching for codes on websites made from WordPress. You can quickly determine where the elements are in the files. In addition, you can find codes in themes, plugins and cores right in the wp admin page.

    All you have to do is select the Tools menu -> select String Locator and enter the code you want to find in the Search string. The plugin will scan through all the theme and plugin files that you have installed, and it will find the search term.

    After you press the Search button and wait a few seconds for the search string results to display, it will declare the file name, location and number of code lines.

    Let me know if my answer can resolve your issue :).

    Thread Starter Mateus Machado Luna

    (@wetah)

    Hi @lucaslitextension, thank you for the answer!

    Unfortunately, it doesn’t fit for my situation, as I have to detect the presence of a certain block dynamically, via my plugin code. So what I really need would be a equivalent function to has_block() that could work on widgets, now that the blocks can be inserted via block editor.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Detecting usage of a widget block on a page.’ is closed to new replies.