Foobar Notifications Lite Shortcode

Below, you’ll find a detailed guide on how to add the Foobar Notifications Lite 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 Foobar Notifications Lite Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Foobar Notifications Lite Plugin and the shortcodes it provides:

Plugin Icon
Notification Bar, Announcement and Cookie Notice WordPress Plugin – FooBar

"FooBar Notification Bar, Announcement and Cookie Notice WordPress Plugin is an essential tool for your website. It allows you to manage announcements, notifications, and cookie notices efficiently."

★★★★☆ (8) Active Installs: 3000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [foobar_shortcode]

Foobar Notifications Lite [foobar_shortcode] Shortcode

The foobar-notifications-lite plugin shortcode is designed to render notification bars on a WordPress site. It accepts ‘id’ as an attribute, which corresponds to the specific notification bar instance. This shortcode retrieves the notification bar instance based on the provided ‘id’. If the bar is inline, it renders immediately. If not, the bar is enqueued for later display. Shortcode: [foobar_shortcode]

Shortcode: [foobar_shortcode]

Parameters

Here is a list of all possible foobar_shortcode shortcode parameters and attributes:

  • id – Unique identifier for the notification bar to display

Examples and Usage

Basic example – In this example, we are using the shortcode to display a Foobar notification bar by referencing its ID. The ID is set to 1.

[foobar_shortcode id=1 /]

Advanced examples

Here, we are using the shortcode to display a Foobar notification bar by referencing its ID and applying additional parameters. The ID is set to 2 and we are also specifying the status of the bar as ‘publish’.

[foobar_shortcode id=2 status='publish' /]

In this example, we are demonstrating how to use the shortcode with multiple parameters. The ID is set to 3, the status is ‘publish’, and we are also specifying the inline property of the bar as true.

[foobar_shortcode id=3 status='publish' inline=true /]

PHP Function Code

In case you have difficulties debugging what causing issues with [foobar_shortcode] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( foobar_shortcode(), array( $this, 'render' ) );

Shortcode PHP function:

                    function render( $atts ) {
			$args = wp_parse_args( $atts, array(
				'id' => 0
			) );

			$args = apply_filters( 'foobar_shortcode_atts', $args );

			if ( array_key_exists( 'id', $args ) ) {

				$id = intval( $args['id'] );
				if ( $id > 0 ) {

					$instance = foobar_get_instance( $id );
					if ( $instance !== false ) {
						//need to check if the bar is inline, and render it immediately
						if ( $instance->is_inline() ) {

							Enqueue::instance()->set_inline_bar_to_shown();

							ob_start();

							foobar_render_bar( $instance, $args, 'publish' );

							$output_string = ob_get_contents();
							ob_end_clean();
							return $output_string;

						} else {
							//enqueue the bar
							foobar_enqueue_bar( $id, $args );

							//output some HTML comments
							return "<!-- FOOBAR_SHORTCODE id:{$id} -->";
						}
					}
				}
			}
		}
                    

Code file location:

foobar-notifications-lite/foobar-notifications-lite/includes/front/class-shortcode.php

Conclusion

Now that you’ve learned how to embed the Foobar Notifications Lite 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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *