If you have a server side rendered block in the backend, it is rendered via the REST API endpoint /wp/v2/block-renderer/xyz/blockname
. This endpoint calls your render function. In the frontend the render function is called directly. The function is_admin()
checks if a backend page was requested. In a REST API Request is no backend page, so the function returns false
on REST API requests.
Instead you can check, if it is a REST API request via:
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
return 'Backend';
} else {
return 'Frontend';
};
Related Posts:
- How to serialize a Gutenberg block from block attributes in PHP?
- Removing Default Gutenberg Blocks, But Keeping Reusable Block Functionality?
- Gutenberg Blocks doesn’t render correctly when using do_blocks
- add_meta_boxes action with refresh on save
- Gutenberg custom block using only register_block_type() and HTML
- Include a Gutenberg Block in a PHP file
- Create custom blocks for bootstrap
- How to return output of the new wp gallery block for automatically Link images To Media file
- Register JS for block on frontend only
- Displaying admin notices inside the block editor from rest_after_insert_{$this->post_type} hook
- How to programmatically add Gallery Block to Existing Post Content
- Best way to add more options to Gutenberg “More Rich” text controls drop down
- Fetch post block/field data as JSON with WordPress API
- Gutenberg block – Save PHP function’s output as HTML?
- Where to find documentation for CPT block template? (PHP)
- Generate YouTube image thumbnail in a Gutenberg block – ACF + Timber
- Add class to group inner container
- Multiple requests external data api dynamic block gutenberg
- How to keep the capability of users and disable Gutenberg editor in WordPress?
- parsing nested blocks (in columns, etc) via PHP
- Passing the name of selected color from the custom component to `render_callback`
- InnerBlocks with allowedBlocks not working with acf_register_block
- Guttenburg and Classic Editor – How to use the custom guttenburg block in classic editor?
- How to render a block from php template
- Want to unrestrict plugin block
- WordPress – Get Posts with Category data
- Additional file upload in Gutenberg page options/featured image
- Add Block Before Entry Title Using PHP
- How to populate a Gutenberg select field SelectControl with option value from PHP array
- Gutenberg Blocks and get_option() for styling
- How to extend SelectControl with data from my theme
- Copying and pasting to WordPress “code editor” code via the front end and clipboard
- Gutenberg block don’t save rich text content
- Is there a PHP function that will return the block ID generated by WordPress?
- register_block_type is not working properly
- Categories does not show Block editor WordPress
- Block that renders html saved in a php file
- Show Gutenberg facebook embed with a custom theme
- Gutenberg – render_callback does not pass ToggleControl value on frontend
- Add default block css when the block has been added with php?
- Custom Post Type doesn’t have template content when creating programmatically in PHP but does when created in WP Admin
- How to add different menu items on different menus?
- How to enable REST API on custom post type without Gutenberg?
- Replace block content with an array
- Include a static block inside of a dynamic block
- WordPress Block Editor Gutenberg running code inside ! is_admin()
- What do ++ and *+ mean?
- Easy way to process search results before displaying
- Who’s job is it to load a plugin’s translated strings?
- Getting movie and serial on actor page
- AJAX / Read More: multiple check_ajax_referer() and wp_create_nonce() not working independentely
- How to get a list of all users registered before a given date?
- WP_User_Query order by meta_key that is an array
- How the functions in WP are called in tags
- Is the outdated PHP mysql extension a requirement for WordPress 4.6?
- Get category name from custom loop and echo it once
- Cannot get media type from ‘x-mapp-php5’
- create a select input with menus created on a custom options page
- Fatal Error relating to sessions.php
- How to change home or site url using action hooks or filter?
- WordPress Configuration with SELinux on CentOS 8
- Error on wp_default_style After upgrade to php 7
- WooCommerce: How can I get orders with a custom ID in order meta data object?
- What is the alternative to “ when it comes to calling Media (image) files in the ‘attachment.php’ file?
- Two queries for a WP_User_Query search work perfectly apart, but not together
- Modify function to print tags/categories/exclude tags/categories/ number of posts
- add_action taking an array with the 2nd argument?
- PHP nested If statement syntax
- WP Insert Post and then go to post
- plugin add action hook is not working :
- customize wordpress database error page
- How can I hook into the wp_mail function used by BackWPup?
- Cannot access $wpdb, comes back NULL
- Get the users that my following users are following
- How do I query a single data value from the wp_metadata table?
- Add a counter for mouseovers (custom field)
- Need to remove ‘Featured’, ‘Date’ and ‘Comments’ from WordPress Sticky Post?
- Convert all uploaded PNG files to PNG-8 format
- Remove Custom Post Category In WordPress Slug Using .Htaccess
- How to set all External Domain Links with nofollow Attribute from Header Footer Content and Excerpt using PHP?
- WordPress Post Block Element not properly parsed with the_content filter
- Possible way of having multiple Gutenberg instances for a page?
- How to display only specific Error types in debug.log? No notices, warnings, etc
- file_get_contents returning different in filters and actions
- WP + MySql db / PHP
- Populate Posts based on category selected using AJAX that means without page refresh
- random woocommerce categories are not showing when count enabled?
- Submit to itself don’t work
- WooCommerce – Add product category below product price [closed]
- Font rendering problem after using include in functions file
- Using Custom Javascript and pHp to send email to myself when a user clicks on an input button but only works on Chrome, IE, and Micorosft Edge
- Can someone help me edit the code for limiting image dimensions
- Access preview settings in php
- custom field meta-box with dropdown/autocomplete
- Removing all my hardcoded URLs with get_site_url()
- Submenu opened problem
- ACF | WooCommerce | Theme Development | How to include a /template-part/ that makes use of ACF’s on a custom WooCommerce homepage?
- append special url end of my website urls
- REST API custom endpoints for metaboxes
- how can i link threejs in my functions.php file in understrap theme