Social Share Button Shortcode

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

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

Plugin Icon
Social Share Button

"Social Share Button is a WordPress plugin designed to enhance your website's social media presence. It empowers users to easily share your content across multiple social networks, expanding your reach and engagement."

★★★★✩ (17) Active Installs: 2000+ Tested with: 6.2.3 PHP Version: false
Included Shortcodes:
  • [social_share_button]

Social Share Button [social_share_button] Shortcode

The Social Share Button shortcode allows users to select a theme for their social share buttons. It fetches the theme settings and custom CSS from the database, then displays the buttons accordingly. The shortcode generates HTML and CSS for the buttons, which can be customized via the ‘themes’ attribute. It also enqueues the style file for the selected theme. The generated HTML is then outputted, allowing users to share content on various social media platforms.

Shortcode: [social_share_button]

Examples and Usage

Basic example – The shortcode displays the social share button with the default theme.

[social_share_button /]

Advanced examples

Displaying the social share button with a specific theme. If the specified theme is not found, it will revert to the default theme.

[social_share_button themes='theme2' /]

Adding multiple attributes to the shortcode. This example demonstrates how to use multiple attributes to customize the social share button’s appearance and behavior. The shortcode will first try to load the theme by ID, but if not found, it will try to load by title.

[social_share_button themes='theme3' custom_css='your_custom_css' /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'social_share_button', array( $this, 'social_share_button_display' ) );

Shortcode PHP function:

function social_share_button_display($atts, $content = null ) {

        $atts = shortcode_atts(
            array(
                'themes' => 'theme1',
                ), $atts);

        $html = '';

        $social_share_button_settings = get_option( 'social_share_button_settings' );
        $theme = $social_share_button_settings['theme'];
        $custom_css = $social_share_button_settings['custom_css'];
        $themes = $theme;


        //$themes = $_GET['themes'];


        $class_social_share_button_functions = new class_social_share_button_functions();
        $social_share_button_themes_dir = $class_social_share_button_functions->social_share_button_themes_dir();
        $social_share_button_themes_url = $class_social_share_button_functions->social_share_button_themes_url();

        ob_start();

        wp_enqueue_style('social_share_button-'.$themes, $social_share_button_themes_url[$themes].'/style.css');


        include $social_share_button_themes_dir[$themes].'/index.php';

        echo $html;


        ?>
        <style type="text/css"><?php echo $custom_css; ?></style>
        <?php

        return ob_get_clean();




    }

Code file location:

social-share-button/social-share-button/includes/class-shortcodes.php

Conclusion

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