Below, you’ll find a detailed guide on how to add the Widgets on Pages Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Widgets on Pages Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Widgets on Pages Plugin and the shortcodes it provides:
"Widgets on Pages is a WordPress plugin designed to easily add widgets to your pages. It enhances user interface, improves site functionality, and enables seamless widget integration."
- [widgets_on_pages]
Widgets on Pages [widgets_on_pages] Shortcode
The ‘widgets_on_pages’ shortcode is a powerful tool in WordPress that allows users to add widgets to their pages. It uses the ‘dynamic_sidebar’ function to display the widget in the specified ‘id’.
Shortcode: [widgets_on_pages]
Parameters
Here is a list of all possible widgets_on_pages shortcode parameters and attributes:
id
– Identifier for the specific widget areatiny
– Sets the size of the widget area to tinysmall
– Sets the size of the widget area to smallmedium
– Sets the size of the widget area to mediumlarge
– Sets the size of the widget area to largewide
– Sets the size of the widget area to wide
Examples and Usage
Basic Example – Here, we are using the shortcode to display a widget on a page by referencing the widget’s ID. This will load the widget with the specified ID onto the page.
[widgets_on_pages id=1 /]
Advanced Examples
Using the shortcode to display a widget on a page by referencing the widget’s ID and specifying the size attributes. The widget will load with the size parameters defined in the shortcode.
[widgets_on_pages id=1 tiny=2 small=3 medium=2 large=1 wide=1 /]
Using the shortcode to display a widget on a page by referencing the widget’s ID and specifying the size attributes. The widget will load with the size parameters defined in the shortcode. If a widget with the specified ID is not found, an error message will be displayed.
[widgets_on_pages id=2 tiny=1 small=1 medium=1 large=2 wide=2 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [widgets_on_pages]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'widgets_on_pages', array( $this, 'widgets_on_page' ) );
Shortcode PHP function:
function widgets_on_page( $atts ) {
foreach ($atts as &$value) {
$value = esc_attr($value);
}
extract( shortcode_atts( array( 'id' => '1', 'tiny' => '1', 'small' => '1', 'medium' => '1', 'large' => '1', 'wide' => '1' ), $atts ) );
$str = "<div id='" . str_replace( ' ', '_', $id ) . "' class='widgets_on_page wop_tiny" . $tiny . ' wop_small' . $small . ' wop_medium' . $medium . ' wop_large' . $large . ' wop_wide' . $wide ."'>
<ul>";
// Legacy bullshit.
if ( is_numeric( $id ) ) {
$id = 'wop-' . $id;
}
ob_start();
if ( function_exists( 'dynamic_sidebar' ) && dynamic_sidebar( $id ) ) {
$my_str = ob_get_contents();
} else {
// Ouput somethign nice to the source.
$my_str = '<!-- ERROR NO TURBO SIDEBAR FOUND WITH ID ' . $id . '-->';
}
ob_end_clean();
$str .= $my_str;
$str .= '</ul></div><!-- widgets_on_page -->';
return $str;
}
Code file location:
widgets-on-pages/widgets-on-pages/public/class-widgets-on-pages-public.php
Conclusion
Now that you’ve learned how to embed the Widgets on Pages Plugin shortcode, 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