How do I add social sharing buttons?

I am on WordPress and I can easily add a plugin, but that increases load time, looks common and old.

I am using the Brook theme, which a minimal theme. (http://www.defensionem.com/7th-and-3rd-fleet-to-be-combined/)

Read More

If you notice, only end at the blog I have my sharing options, Such as Facebook, Linkedin, Twitter.

Can I enable this in the Sidebar widget? I contacted my theme author and they said to me,

“Our social-sharing links are built in brook/share_block.php. You
could try creating a new custom widget, and use the code from
share_block.php. Alternatively, you could use a Text Widget, and input
directly html code for sharing. By using the markup and classes as we
did, you should be able to get the same style.”

Here’s my that php file. I tried various methods but it did not work. Guess everything is wrong.

Can you all help?

<?php

$theme_settings = brook_theme_settings();

if( has_post_thumbnail() ){
    $share_image            = wp_get_attachment_image_src( get_post_thumbnail_id(), 'xxl' );
    $share_image            = $share_image[0];
    $share_image_portrait   = wp_get_attachment_image_src( get_post_thumbnail_id(), 'portrait-m' );
    $share_image_portrait   = $share_image_portrait[0];
}else{
    $share_image            = '';
    $share_image_portrait   = '';
}

$share_excerpt = strip_tags( get_the_excerpt(), '<b><i><strong><a>' );


?>

<div class="social-nav social-nav--titles">

    <ul class="social-nav__items">


        <?php if( $theme_settings['sharing_email'] ): ?>
            <li class="social-nav__item">
                <a title="<?php _e( 'Email', 'brook' ); ?>" class="social-nav__link js-skip-ajax" href="mailto:?subject=<?php echo ( rawurlencode( get_the_title() ) ); ?>&amp;body=<?php echo ( rawurlencode ( $share_excerpt . ' ' . get_the_permalink() ) ); ?>">
                    <?php _e( 'Email', 'brook' ); ?>
                </a>
            </li>
        <?php endif; ?>

        <?php if( $theme_settings['sharing_facebook'] ): ?>
            <li class="social-nav__item">
                <a title="<?php _e( 'Facebook', 'brook' ); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="http://www.facebook.com/sharer.php?u=<?php echo( rawurlencode( get_the_permalink() ) ); ?>">
                    <?php _e( 'Facebook', 'brook' ); ?>
                </a>
            </li>
        <?php endif; ?>

        <?php if( $theme_settings['sharing_twitter'] ): ?>
            <li class="social-nav__item">
                <a title="<?php _e( 'Twitter', 'brook' ); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank"  href="http://twitter.com/intent/tweet?text=<?php echo( rawurlencode( get_the_title() ) ); ?>&amp;url=<?php echo( rawurlencode( get_the_permalink() ) ); ?>">
                    <?php _e( 'Twitter', 'brook' ); ?>
                </a>
            </li>
        <?php endif; ?>

        <?php if( $theme_settings['sharing_pinterest'] ): ?>
            <li class="social-nav__item">
                <a title="<?php _e( 'Pinterest', 'brook' ); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="http://pinterest.com/pin/create/button/?url=<?php echo( rawurlencode( get_the_permalink() ) ); ?>&amp;media=<?php echo ( rawurlencode( $share_image_portrait ) ); ?>&amp;description=<?php echo( rawurlencode( get_the_title() ) ); ?>">
                    <?php _e( 'Pinterest', 'brook' ); ?>
                </a>
            </li>
        <?php endif; ?>

        <?php if( $theme_settings['sharing_google'] ): ?>
            <li class="social-nav__item">
                <a title="<?php _e( 'Google+', 'brook' ); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="https://plus.google.com/share?url=<?php echo( rawurlencode( get_the_permalink() ) ); ?>">
                    <?php _e( 'Google+', 'brook' ); ?>
                </a>
            </li>
        <?php endif; ?>
        <?php if( $theme_settings['sharing_linkedin'] ): ?>
            <li class="social-nav__item">
                <a title="<?php _e( 'LinkedIn', 'brook' ); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=<?php echo( rawurlencode( get_the_permalink() ) ); ?>&amp;title=<?php echo( rawurlencode( get_the_title() ) ); ?>&amp;summary=<?php echo ( rawurlencode ( $share_excerpt ) );?>&amp;source=<?php echo ( rawurlencode( get_bloginfo('name') ) );?>">
                    <?php _e( 'LinkedIn', 'brook' ); ?>
                </a>
            </li>
        <?php endif; ?>

    </ul>
</div>

Related posts

2 comments

  1. Well What I suggest you which is the easiest solution is first install a plugin from this link https://wordpress.org/plugins/php-code-widget/
    It ia a plugin when you activate it, it creates a widget in which you can put your all php code from your required file. As far as the styling is concerned you can add the relevant styling to main css file of your Brook theme. I hope it helps….

Comments are closed.