Below, you’ll find a detailed guide on how to add the Social Rocket – Social Sharing 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 Social Rocket – Social Sharing Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Social Rocket – Social Sharing Plugin and the shortcodes it provides:
"Social Rocket – Social Sharing Plugin is a dynamic WordPress tool designed to boost your site's social media engagement. It enables easy social sharing for increased traffic."
- [socialrocket]
- [socialrocket-floating]
- [socialrocket-tweet]
Social Rocket – Social Sharing [socialrocket] Shortcode
The Social Rocket shortcode integrates social sharing buttons into your WordPress site. It’s designed to be flexible, allowing customization based on specific conditions. The shortcode checks if the page is an AMP page or a feed, halting execution if either is true. It then confirms the attributes are in an array format. The shortcode allows the addition of a class to the social buttons, and determines whether to display the buttons based on the ‘inline_mobile_setting’. The shortcode can be modified to display different social buttons for desktop and mobile, or to display all buttons. This is controlled through the ‘inserts’ array, which is filterable for further customization. Finally, the shortcode generates the HTML for the social buttons and returns the output. This shortcode provides a simple yet powerful way to add social sharing to your WordPress site.
Shortcode: [socialrocket]
Examples and Usage
Basic example – The shortcode is used to display social sharing buttons without any additional classes.
[socialrocket /]
Advanced examples
Adding an additional class to the social sharing buttons. The class ‘custom-class’ will be added to the buttons, allowing for extra customization with CSS.
[socialrocket add_class='custom-class' /]
Displaying social sharing buttons that are only visible on desktop devices. The ‘desktop-only’ class is added to the buttons, making them hidden on mobile devices.
[socialrocket add_class='desktop-only' /]
Adding multiple classes to the social sharing buttons. The classes ‘custom-class1’ and ‘custom-class2’ are added to the buttons, allowing for more complex customization with CSS.
[socialrocket add_class='custom-class1 custom-class2' /]
PHP Function Code
In case you have difficulties debugging what causing issues with [socialrocket]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'socialrocket', 'social_rocket_shortcode' );
Shortcode PHP function:
function social_rocket_shortcode( $atts = array() ) {
// if we're loading on an AMP page, stop here (our styles won't be available anyway)
if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
return;
}
// if this is a feed, stop here
if ( is_feed() ) {
return;
}
// just a double check
if ( ! is_array( $atts ) ) {
$atts = array();
}
$SR = Social_Rocket::get_instance();
$output = '';
$add_class = $SR->_isset( $atts['add_class'], '' );
$inserts = array();
if ( $SR->settings['inline_mobile_setting'] === 'disabled' ) {
$inserts[] = array( 'where' => 'shortcode', 'what' => 'desktop-only' );
} else {
$inserts[] = array( 'where' => 'shortcode', 'what' => 'all' );
}
$inserts = apply_filters( 'social_rocket_inline_buttons_inserts', $inserts );
$SR->data['doing_shortcode'] = 'inline';
foreach ( $inserts as $insert ) {
if ( $insert['where'] !== 'shortcode' ) {
continue;
}
if ( $insert['what'] === 'all' ) {
// no add_class
$output .= $SR->get_inline_buttons_html( $atts );
} else {
if ( is_array( $insert['what'] ) ) {
// multiple add_classes
foreach ( $insert['what'] as $what ) {
$atts['add_class'] = $add_class . ' social-rocket-'.$what;
$output .= $SR->get_inline_buttons_html( $atts );
}
} else {
// single add_class
$atts['add_class'] = $add_class . ' social-rocket-'.$insert['what'];
$output .= $SR->get_inline_buttons_html( $atts );
}
}
}
$SR->data['doing_shortcode'] = false;
return $output;
}
Code file location:
social-rocket/social-rocket/includes/social-rocket-shortcodes.php
Social Rocket – Social Sharing [socialrocket-floating] Shortcode
The Social Rocket Floating shortcode is a handy tool for adding floating social share buttons to your site. This shortcode triggers the ‘social_rocket_floating_shortcode’ function. It checks if the passed attributes are an array, and if not, it creates one. The Social Rocket instance is then fetched, and the ‘doing_shortcode’ data is set to ‘floating’. The function then generates the HTML for the floating buttons using the given attributes. Once the HTML is generated, the ‘doing_shortcode’ data is set back to false. The HTML for the floating buttons is then returned and displayed on the webpage.
Shortcode: [socialrocket-floating]
Examples and Usage
Basic example – Displaying the default floating social share buttons using the ‘socialrocket-floating’ shortcode.
[socialrocket-floating /]
Advanced examples
Displaying the floating social share buttons with custom attributes. In this example, we are setting the ‘networks’ attribute to ‘facebook,twitter,linkedin’ which will only show these three social networks on the floating buttons. The ‘position’ attribute is set to ‘left’ which will position the floating buttons to the left side of the page.
[socialrocket-floating networks="facebook,twitter,linkedin" position="left" /]
In this next advanced example, we are setting the ‘show_counts’ attribute to ‘true’ which will display the share counts next to each floating button. The ‘total_shares’ attribute is also set to ‘true’ to display the total number of shares across all networks.
[socialrocket-floating show_counts="true" total_shares="true" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [socialrocket-floating]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'socialrocket-floating', 'social_rocket_floating_shortcode' );
Shortcode PHP function:
function social_rocket_floating_shortcode( $atts = array() ) {
// just a double check
if ( ! is_array( $atts ) ) {
$atts = array();
}
$SR = Social_Rocket::get_instance();
$SR->data['doing_shortcode'] = 'floating';
$output = $SR->get_floating_buttons_html( $atts );
$SR->data['doing_shortcode'] = false;
return $output;
}
Code file location:
social-rocket/social-rocket/includes/social-rocket-shortcodes.php
Social Rocket – Social Sharing [socialrocket-tweet] Shortcode
The Social Rocket shortcode is a custom function that allows you to display a Twitter share button on your website. It verifies the attributes and calls the get_tweet_code function.
Shortcode: [socialrocket-tweet]
Examples and Usage
Basic example – In this example, we are using the Social Rocket Tweet shortcode without any parameters. This will generate a default tweet button with standard settings.
[socialrocket-tweet /]
Advanced examples
Here, we are passing a ‘url’ attribute to the shortcode. This attribute will specify the URL that the tweet button should link to. If this attribute is not provided, the button will link to the current page.
[socialrocket-tweet url="http://example.com" /]
In this next example, we are passing a ‘text’ attribute. This attribute will specify the text that should be included in the tweet when the button is clicked. If this attribute is not provided, the tweet will include the title of the current page.
[socialrocket-tweet text="Check out this great article!" /]
Finally, we can combine multiple attributes to customize the tweet button further. In this example, we are specifying both the URL and the tweet text.
[socialrocket-tweet url="http://example.com" text="Check out this great article!" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [socialrocket-tweet]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'socialrocket-tweet', 'social_rocket_tweet_shortcode' );
Shortcode PHP function:
function social_rocket_tweet_shortcode( $atts = array() ) {
// just a double check
if ( ! is_array( $atts ) ) {
$atts = array();
}
$SR = Social_Rocket::get_instance();
$SR->data['doing_shortcode'] = 'tweet';
$output = $SR->get_tweet_code( $atts );
$SR->data['doing_shortcode'] = false;
return $output;
}
Code file location:
social-rocket/social-rocket/includes/social-rocket-shortcodes.php
Conclusion
Now that you’ve learned how to embed the Social Rocket – Social Sharing 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