Skip to content

Add Shortcodes Before and After Beaver Builder Rows to Restrict Content Based on Membership

Easily Restrict Beaver Builder Row Content with Shortcodes

Working with membership plugins with Beaver Builder is more difficult than it needs to be. Most of the time you’re stuck restricting entire pages when all you really want to restrict is a certain row. You could use the ‘Visibility’ options and limit by capability but not all membership plugins utilize user capability and it still doesn’t give you all of the options that you have when using your favorite plugin’s shortcodes. Let’s solve that.

I’ve put together a quick bit of code that will add a tab to the settings panel of all your rows that will allow you to put a before shortcode and an after shortcode just like if you were using the default WordPress text editor. You can either download my plugin (this is the second module added to it) from the WordPress repository here or add this code to your child theme’s functions.php file:

add_filter( 'fl_builder_register_settings_form', function ( $form, $id ) {
    if ( 'row' == $id ) {
        $form['tabs']['mr-rows'] = [
            'title' => __('Row Shortcodes', 'mr-modules'),
            'sections' => [
                'row_shortcodes' => [
                    'title'  => __('Before & After Row Shortcodes', 'mr-modules'),
                    'fields' => [ 
                        'enable_shortcodes' => [
                            'type' => 'select',
                            'label' => __( 'Before and After Shortcodes', 'mr-modules' ),
                            'default' => 'no',
                            'options' => [ 
                                'yes' => __('Yes', 'mr-modules'),
                                'no' => __('No', 'mr-modules')
                            ],
                            'toggle'    => [
                                'yes'   => [
                                    'fields'    => ['before_shortcode', 'after_shortcode']
                                ],
                                'no'    => []
                            ]
                        ],
                        'before_shortcode'  => [
                            'type'  => 'text',
                            'label' => __('Before row shortcode', 'mr-modules')
                        ],
                        'after_shortcode'   => [
                            'type'  => 'text',
                            'label' => __('After row shortcode', 'mr-modules')
                        ]

                    ]
                ]
            ]
        ];        
    }

    return $form;
}, 10, 2 );


add_action( 'fl_builder_before_render_row', function( $row, $groups ) {
    if ( $row->settings->enable_shortcodes == 'yes' && !empty($row->settings->before_shortcode) && !empty($row->settings->after_shortcode) ) {
        echo $row->settings->before_shortcode;
    }
}, 10, 2 );

add_action( 'fl_builder_after_render_row', function( $row, $groups ) {
    if ( $row->settings->enable_shortcodes == 'yes' && !empty($row->settings->before_shortcode) && !empty($row->settings->after_shortcode) ) {
        echo $row->settings->after_shortcode;
    }
}, 10, 2 );

Thanks for looking!

If you use this code and like it I’d really appreciate a rating on the Media Recode Facebook page or on the WordPress repository. If you need any custom modules, website help, hosting or content management please get in touch below and I’d love to talk!

Get In Touch

    Select any services you're interested in.
  • This field is for validation purposes and should be left unchanged.