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()
- Manipulating the allowed inner blocks of a core-gutenberg-block?
- Adding features to Gutenberg without theme.json
- Registering a custom block style
- Get column block count using PHP method render_block
- do_blocks not working with a custom block
- How to edit templates created in the block editor in code / template files not updating
- Programmatically convert single classic block to individual blocks via PHP
- Add custom data attribute to every core Gutenberg Blocks
- Embed dynamic media query in a Gutenberg block
- Get generated block styles programmatically
- When a foreach loop is used multiple times in blocks, is there a way to ensure a variable always has a unique value?
- How to get the post title inside a custom block in a loop? block.js
- How to display only the first 2 words of a post title
- How to get the content of a dynamic block in PHP
- Set custom post type to load custom block pattern by default
- How to set and use global variables? Or why not to use them at all
- What is in media-template.php, and how does it work?
- Set the transport of the Customizer ‘header_image’ core setting to ‘postMessage’
- How to disable wordpress confirmation email for new users
- tag search using WP_Query
- Retrieving all data from repeater fields
- Loading page template into shortcode
- Unable to post simple form data in HTML
- dynamic sidebar not showing anything
- How to implement Google Tag Manager? [closed]
- How to remove or change the “W” icon in “My Sites”?
- Show all posts by author
- 200 Rewrite blog post links
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- code is skipping a div
- How to use wp_add_inline_style for custom CSS added via shortcode?
- Form Security: nonce vs. jQuery
- Normal PHP array for exclude section of WordPress query?
- Buddypress update user avatar image via REST
- Accessing $post after PHP is executed
- How to Change CSS Colors from Custom Plugin Settings Page
- How to relocate paypal button gateway on checkout page in woocommerce
- Admin submenu issue with PHP not detecting two strings as equal
- PHP- Why is my contact form keep showing it is invalid? [closed]
- WordPress database html table with pagination
- Prepend to all image URLs with PHP, only for mobile devices
- Cant get blog name with get_option
- Force REST API Authentication for each request method
- Adding if statement
- Editing the term_order field
- How to display dual language menus and headers?
- How to create a sub-page of sub-page?
- How to hide the Duplicate taxonomy values in WordPress?
- Trying to display user meta by “name” – not by “ID”
- Redirect homepage /page/1/ to /blog/page/1/
- Fluid Featured Post Carousel Slider for WordPress with no Javascript
- php “use” not working in template [closed]
- Load slideshow.css file only if Slideshow is checked / on
- PHP warning $post->ID is null