• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

RESOLVED Gutenberg Editor can not update when using Snippets

liamerven

New member
Messages
3
Likes
0
Points
1
#1
I have a universal snippet that runs in my header to register some functions. When I add a snippet to my post referring to the function in the header, my editor keeps complaining about not being able to update. Checking my error.log shows that the function can't be found. However viewing the page works perfectly fine. What I'm wondering is, if the admin page not running these header code snippets. If not, then how can I fix this? I'd prefer that my editor work properly. Any help is appreciated.
 

Kirill

Support team
Messages
82
Likes
4
Points
8
#2
Hello

Safe mode may help you. This will disable snippet execution.
  1. Go to the safe mode by this link: http://your-site-name.dev/wp-admin/?wbcr-php-snippets-safe-mode
  2. Edit the snippet;
  3. Leave safe mode by clicking the link: http://your-site-name.dev/wp-admin/?wbcr-php-snippets-disable-safe-mode

Do you use gutenberg or classic editor?
Please put here your snippet code. This will help us find a bug.

Best regards
 

liamerven

New member
Messages
3
Likes
0
Points
1
#3
Hello

Safe mode may help you. This will disable snippet execution.
  1. Go to the safe mode by this link: http://your-site-name.dev/wp-admin/?wbcr-php-snippets-safe-mode
  2. Edit the snippet;
  3. Leave safe mode by clicking the link: http://your-site-name.dev/wp-admin/?wbcr-php-snippets-disable-safe-mode

Do you use gutenberg or classic editor?
Please put here your snippet code. This will help us find a bug.

Best regards
I am using Gutenberg as my editor. I did run a quick test by having a global snippet write text to the top of the page. I noticed that it worked everywhere except the admin area which leads me to believe that snippets aren't being called in the admin area which then causes problems with gutenberg as it wants to refer to functions that haven't been registered yet.
Is there a way to tell the admin pages to use snippets in their headers? I imagine this would solve my updating issues.
 

Kirill

Support team
Messages
82
Likes
4
Points
8
#4
If you want run snippet in admin area then you need create "php snippet" instead "universal".
Automatic insertion "head" for frontend. We will add options for admin pages in future.

In php snippet you can use "in_admin_header", "admin_head" or "admin_init" hook:
  • admin_init - for declare functions and more
  • admin_head - for print something into <head></head> tag on admin pages
  • in_admin_header - print something before main content on admin pages

Set "run everywhere" option.

PHP:
function my_admin_something(){
       // your code here
}

add_action('in_admin_header', 'my_admin_something');
Best regards