Skip to Content


Display more optimized and consistently styled, non-native social sharing buttons.

PHP February 14, 2019


nebula()->share($networks, $id);


(Optional) (Array) An array of social networks to display
Default: None

(Optional) (Integer) A post ID to share
Default: None

Parameter Notes

If no $id is provided, the current post is used.

Request or provide clarification »


<?php echo nebula()->share(array('shareapi', 'facebook', 'twitter', 'linkedin', 'pinterest', 'email')); ?>
Was this page helpful? Yes No

    A feedback message is required to submit this form.

    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Functions.php on line 1020.

    1 Hook

    Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

    Need a new filter hook? Request one here.

    This function has no action hooks available. Request one?

    Note: This function contains 1 to-do comment.

            public function share($networks=array('shareapi', 'facebook', 'twitter'), $id=false){
                $override = apply_filters('pre_nebula_share', null, $networks, $id);
                if ( isset($override) ){return;}
                //@todo "Nebula" 0: Use null coalescing operator here if possible
                if ( empty($id) ){
                    $id = get_the_id();
                $encoded_url = urlencode(get_permalink($id));
                $encoded_title = urlencode(get_the_title($id));
                //Convert $networks to lower case without dashes/spaces for more flexible string matching later.
                $networks = array_map(function($value){
                    return str_replace(array(' ', '_', '-'), '', strtolower($value));
                }, $networks);
                echo '<div class="sharing-links">';
                //If the 'shareapi' cookie exists and 'shareapi' is requested, return *only* the Share API
                if ( isset($this->super->cookie['shareapi']) || in_array($networks, array('shareapi')) ){
                    $networks = array('shareapi');
                foreach ( $networks as $network ){
                    //Share API
                    if ( in_array($network, array('shareapi')) ){
                        echo '<a class="nebula-share-btn nebula-share shareapi" href="#">' . __('Share', 'nebula') . '</a>';
                    if ( in_array($network, array('facebook', 'fb')) ){
                        echo '<a class="nebula-share-btn facebook" href="' . $encoded_url . '&t=' . $encoded_title . '" target="_blank" rel="noopener">' . __('Share', 'nebula') . '</a>';
                    if ( in_array($network, array('twitter')) ){
                        echo '<a class="nebula-share-btn twitter" href="' . $encoded_title . '&url=' . $encoded_url . '" target="_blank" rel="noopener">' . __('Tweet', 'nebula') . '</a>';
                    if ( in_array($network, array('linkedin', 'li')) ){
                        echo '<a class="nebula-share-btn linkedin" href="' . $encoded_url . '&title=' . $encoded_title . '" target="_blank" rel="noopener">' . __('Share', 'nebula') . '</a>';
                    if ( in_array($network, array('pinterest', 'pin')) ){
                        echo '<a class="nebula-share-btn pinterest" href="' . $encoded_url . '" target="_blank" rel="noopener">' . __('Share', 'nebula') . '</a>';
                    if ( in_array($network, array('email')) ){
                        echo '<a class="nebula-share-btn email" href="mailto:?subject=' . $encoded_title . '&body=' . $encoded_url . '" target="_blank" rel="noopener">' . __('Email', 'nebula') . '</a>';
                echo '</div><!--/sharing-links-->';


    To override this PHP function, use this hook in your child theme or plugin ("my_custom" can be changed):

    add_filter('pre_nebula_share', 'my_custom_share', 10, 3); //The last integer must be 1 more than the actual parameters
    function my_custom_share($null, $networks, $id){ //$null is required, but can be ignored
        //Write your own code here
        return true; //Return true to prevent the original function from running afterwords

    You can completely disable this PHP function with a single line actions:

     add_filter('pre_nebula_share', '__return_false');