Headless Website setup issue and bugfix suggestion

#908140
  • Resolved Aaron Reimann
    Rank Math free

    Hello!

    Our website uses a headless setup with GraphQL, FaustJS, Next.js, and the Sage theme.

    We’ve encountered an issue with the RankMath Free plugin file at:
    \plugins\seo-by-rank-math\includes\modules\schema\class-snippet-shortcode.php

    This file is causing frontend build failures with the following error:

    Function WP_Block_Type_Registry::register was called incorrectly. Block type “rank-math/rich-snippet” is already registered. Please see Debugging in WordPress for more information. (This message was added in version 5.0.0.)

    Would it be possible to add a fix to line 57 of class-snippet-shortcode.php as follows?
    https://pastebin.com/A8NaFpTS

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello,

    We apologize for the issue you are facing with your headless setup and the Rank Math plugin. Thank you for raising this concern regarding the frontend build failures caused by the class-snippet-shortcode.php file.

    The error message indicates that the block type rank-math/rich-snippet is being registered multiple times, which is indeed a problem. Your suggested fix to check if the block is already registered before attempting to register it again is a good approach.

    Here’s a summary of your proposed code:

    $block_registry = WP_Block_Type_Registry::get_instance();
    if (!$block_registry->is_registered('rank-math/rich-snippet')) {
        register_block_type(
            'rank-math/rich-snippet',
            [
                'render_callback' => [$this, 'rich_snippet'],
                'attributes' => [
                    'id' => [
                        'default' => '',
                        'type' => 'string',
                    ],
                    'post_id' => [
                        'default' => '',
                        'type' => 'integer',
                    ],
                ],
            ]
        );
    }

    This modification should help prevent the error from occurring by ensuring that the block is only registered if it hasn’t been already.

    Since this issue involves a potential bug fix in the plugin, we recommend replying to your ticket so that a human agent from the Rank Math Support team can take over and address this matter appropriately. They will be able to consider your suggestion and provide further assistance.

    Thank you for your understanding, and we appreciate your contribution to improving our plugin!

    Hello,

    Thank you for contacting us. We apologize for any inconvenience this issue may have caused.

    You can use the following filter to blacklist the rich-snippet blocks from our plugin on the website:

    add_filter( 'allowed_block_types_all', 'blacklist_rm_blocks' );
     
    function blacklist_rm_blocks( $allowed_blocks ) {
        $blocks = WP_Block_Type_Registry::get_instance()->get_all_registered();
    
        unset( $blocks[ 'rank-math/rich-snippet' ] );
        
        return array_keys( $blocks );
    }

    Here’s how you can add filter/hook to your WordPress site: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Please note that any pages that are already using the blocks will continue to use them unless you delete the content from the blog on the pages.

    Don’t hesitate to get in touch if you have any other questions.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)

The ticket ‘Headless Website setup issue and bugfix suggestion’ is closed to new replies.