Below, you’ll find a detailed guide on how to add the Responsive Menu Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Responsive Menu Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Responsive Menu Plugin and the shortcodes it provides:
"Responsive Menu – Create Mobile-Friendly Menu is a dynamic WordPress plugin that allows you to seamlessly create and integrate user-friendly mobile menus into your website."
- [rmp_menu]
- [responsive_menu]
Responsive Menu [rmp_menu] Shortcode
The Responsive Menu Plugin shortcode, ‘rmp_menu’, dynamically generates a menu. It accepts an ‘id’ attribute, which specifies the menu to display. If the ‘id’ attribute is missing or invalid, or if the specified menu isn’t published, an error message is displayed. The shortcode also checks if the ‘shortcode’ option is activated. If not, it returns ‘Shortcode deactivated’. Once validated, it initiates the RMP_Menu class, builds the menu, and returns the output.
Shortcode: [rmp_menu]
Parameters
Here is a list of all possible rmp_menu shortcode parameters and attributes:
id
– The unique identifier for the specific menu you want to display.
Examples and Usage
Basic example – In this basic usage, the shortcode is used to display a responsive menu by referencing the menu id. If the menu is published and the shortcode option is activated, the menu will be displayed. If not, error messages will be returned.
[rmp_menu id=3 /]
Advanced examples
Displaying a responsive menu by referencing the menu id and passing additional attributes. In this advanced usage, the shortcode is used to display a responsive menu with more than one parameter. The additional parameters can be used to customize the appearance and behavior of the menu.
[rmp_menu id=3 theme="dark" position="left" /]
Please note that the ‘theme’ and ‘position’ parameters are hypothetical and depend on the actual options provided by the Responsive Menu Plugin.
PHP Function Code
In case you have difficulties debugging what causing issues with [rmp_menu]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'rmp_menu', array( $this, 'register_menu_shortcode' ) );
Shortcode PHP function:
function register_menu_shortcode( $attrs = array() ) {
$attrs = shortcode_atts( array( 'id' => '' ), $attrs );
$attrs = array_change_key_case( (array) $attrs, CASE_LOWER );
// Check given id is valid.
if ( empty( $attrs['id'] ) ) {
return __( 'Please pass menu id as attribute.', 'responsive-menu' );
}
$menu_id = $attrs['id'];
if ( 'publish' !== get_post_status( $menu_id ) ) {
/* translators: %d: Menu id */
return sprintf( __( 'Shortcode with menu id %d is not published.', 'responsive-menu' ), esc_html( $menu_id ) );
}
// Check shortcode option is activated or not.
$option_manager = Option_Manager::get_instance();
$option = $option_manager->get_option( $menu_id, 'menu_display_on' );
if ( 'shortcode' !== $option ) {
return __( 'Shortcode deactivated', 'responsive-menu' );
}
ob_start();
$menu = new RMP_Menu( $menu_id );
$menu->build_menu();
return ob_get_clean();
}
Code file location:
responsive-menu/responsive-menu/v4.0.0/inc/classes/class-admin.php
Responsive Menu [responsive_menu] Shortcode
The Responsive Menu shortcode is a dynamic tool that generates a responsive menu for your website. It checks whether the shortcode option is activated, then iterates through all menu IDs. If the ‘menu_display_on’ option for a menu ID is set to ‘shortcode’, it initiates the menu build process. If no menus are found or the shortcode is deactivated, it returns a message.
Shortcode: [responsive_menu]
Examples and Usage
Basic example – The following shortcode allows you to display a responsive menu on your website. The shortcode does not require any parameters, as it automatically generates the menu based on your site’s settings.
[responsive_menu /]
PHP Function Code
In case you have difficulties debugging what causing issues with [responsive_menu]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'responsive_menu', array( $this, 'responsive_menu_shortcode' ) );
Shortcode PHP function:
function responsive_menu_shortcode() {
// Check shortcode option is activated or not.
$options = Option_Manager::get_instance();
$menu_ids = get_all_rmp_menu_ids();
if ( ! empty( $menu_ids ) ) {
foreach ( $menu_ids as $menu_id ) {
$menu_show_on = $options->get_option( $menu_id, 'menu_display_on' );
if ( ! empty( $menu_show_on ) && 'shortcode' !== $menu_show_on ) {
continue;
}
ob_start();
$menu = new RMP_Menu( $menu_id );
$menu->build_menu();
return ob_get_clean();
}
} else {
return __( 'Shortcode deactivated', 'responsive-menu' );
}
}
Code file location:
responsive-menu/responsive-menu/v4.0.0/inc/classes/class-admin.php
Conclusion
Now that you’ve learned how to embed the Responsive Menu Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply