Floating Social Bar Shortcode

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

Before starting, here is an overview of the Floating Social Bar Plugin and the shortcodes it provides:

Plugin Icon
Floating Social Bar

"Floating Social Bar is a lightweight, efficient WordPress plugin designed to add a horizontal share bar to your blog posts. It supports major social networks enhancing user interaction and engagement."

★★★★✩ (76) Active Installs: 3000+ Tested with: 4.1.39 PHP Version: false
Included Shortcodes:
  • [fsb-social-bar]

Floating Social Bar [fsb-social-bar] Shortcode

The Floating Social Bar shortcode allows for dynamic display of social media counts. It checks the attributes passed, converts any “true” or “false” values to boolean, and verifies if the service is available. If valid, it retrieves the post’s social count and prepares the output. If no attributes are passed, it uses the user-defined settings. It only proceeds if there are services to output, providing a flexible way to showcase social popularity.

Shortcode: [fsb-social-bar]

Examples and Usage

Basic example – A simple usage of the shortcode to display the social bar on your post or page would be as follows:

[fsb-social-bar /]

This shortcode will call the ‘fsb-social-bar’ function and display the social share buttons as per your default settings in the plugin.

Advanced examples

To display specific social share buttons on your post or page, you can pass the social media service names as attributes in the shortcode. For instance, if you want to display only Facebook and Twitter share buttons, you can use the shortcode as follows:

[fsb-social-bar facebook=true twitter=true /]

This will override your default settings and only display the Facebook and Twitter share buttons.

If you want to exclude a specific service from being displayed, you can set its value to false. For example, to display all services except Pinterest, you can use the shortcode as follows:

[fsb-social-bar pinterest=false /]

This will display all the social share buttons as per your default settings, except for Pinterest.

Remember, the services you can use as attributes are the ones available in your Floating Social Bar plugin settings.

PHP Function Code

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

Shortcode line:

add_shortcode( 'fsb-social-bar', array( $this, 'shortcode' ) );

Shortcode PHP function:

                    function shortcode( $atts ) {

        // Prepare variables.
        global $post;
        $output   = '';
        $has_atts = false;

        // Cast any "true" or "false" attributes to a boolean value.
        foreach ( (array) $atts as $key => $val ) {
            if ( 'true' == $val )
                $atts[$key] = true;
            if ( 'false' == $val )
                $atts[$key] = false;
        }

        // If we have any attributes, set the flag to true.
        if ( ! empty( $atts ) )
            $has_atts = true;

        // If we have attributes, output in the order that they are placed in the attributes.
        if ( $has_atts ) {
            // Loop through the attributes and output the proper code.
            $services 	 = '';
            $has_service = false;
            $available = $this->get_services();
            foreach ( (array) $atts as $service => $bool ) {
                // Pass over any items set to false or if they are not in the services list.
                if ( ! $bool || ! in_array( $service, $available ) ) continue;

                // Set flag to true so that we know to output something on the screen.
                $has_service = true;

                // Retrieve the output.
                $count  = get_post_meta( $post->ID, 'fsb_social_' . $service, true );
                $services .= $this->get_service_output( $service, $count );
            }

            // Only proceed if we actually have services to output.
            if ( $has_service )
            	$output .= $this->do_social_bar_output( $services, $atts, true );
        } else {
            // Otherwise, we will just use the user-defined settings.
            $services 	 = '';
            $has_service = false;
            foreach ( $this->option['services'] as $service => $data ) {
                if ( ! $data['on'] ) continue;

                // Set flag to true so that we know to output something on the screen.
                $has_service = true;

                // Retrieve the output.
                $count  = get_post_meta( $post->ID, 'fsb_social_' . $service, true );
                $services .= $this->get_service_output( $service, $count );
            }

            // Only proceed if we actually have services to output.
            if ( $has_service )
            	$output .= $this->do_social_bar_output( $services );
        }

        // Return the output.
        return $output;

    }
                    

Code file location:

floating-social-bar/floating-social-bar/class-floating-social-bar.php

Conclusion

Now that you’ve learned how to embed the Floating Social Bar 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 *