Copy/Paste WordPress Code for CCarter's Social Share Icon/Buttons (no HTTP Requests Needed)

Joined
Mar 16, 2017
Messages
40
Likes
102
Degree
0
First I need to start off by saying two things:
  1. FUCK YOU PHP (lots of Googling and trial/error to make this for us)
  2. THANK YOU @CCarter (this post is my adaption of his code for PicoCMS/Twig)
tenor.gif

Now that we got that out of the way, let's get started. Please note that this code isn't perfect and that I gave up on the email part. Also, if you're going to use this code you better have a child theme. Here's how to create a WordPress child theme for the BuSo Lightning theme.

In your child theme's functions.php file, I have this code for getting the current page's URL:

PHP:
function curPageURL() {
  if(isset($_SERVER["HTTPS"]) && !empty($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] != 'on' )) {
        $url = 'https://'.$_SERVER["SERVER_NAME"];//https url
  }  else {
    $url =  'http://'.$_SERVER["SERVER_NAME"];//http url
  }
  if(( $_SERVER["SERVER_PORT"] != 80 )) {
     $url .= $_SERVER["SERVER_PORT"];
  }
  $url .= $_SERVER["REQUEST_URI"];
  return $url;
}

This is my modification of CCarter's code that I use on my posts page:

PHP:
<!-- SOCIAL SHARING --><div>

<div class="facebook-button">
<?php echo '<a href="https://www.facebook.com/sharer/sharer.php?u=', curPageURL(); ?>" target="_blank"><i class="fa fa-facebook fa-lg"></i> &nbsp; Share</a></div>

<div class="twitter-button">
<?php echo '<a href="http://twitter.com/share" target="_blank" class="twitter-share-button" data-text=\'', curPageURL(); ?>' data-count="none"><i class="fa fa-twitter fa-lg"></i> &nbsp; Tweet</a></div>

<div class="reddit-button">
<a href="http://www.reddit.com/submit" onclick="window.location = 'http://www.reddit.com/submit?url=' + encodeURIComponent(window.location); return false"><i class="fa fa-reddit fa-lg"></i> &nbsp; Reddit</a></div>

</div><!-- END SOCIAL SHARING -->

Here's my CSS (built it off of elements from the BuSo Lightning theme):

Code:
.facebook-button {background-color: #3b5998;}
.twitter-button {background-color: #00aced;}
.reddit-button {background-color: #FF8b60;}

.facebook-button a, .twitter-button a, .reddit-button a {color:#fff;}

.facebook-button a, .twitter-button a, .reddit-button a {text-decoration: none}

.facebook-button:hover, .twitter-button:hover, .reddit-button:hover {
background-color: #2ecc71;
border: 1px solid #27ae60;}

.facebook-button, .twitter-button, .reddit-button {
    display: inline-block;
    height: 38px;
    padding: 0 30px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    line-height: 38px;
    letter-spacing: .1rem;
    text-transform: uppercase;
    text-decoration: none;
    white-space: nowrap;
    border-radius: 4px;
    border: 1px solid #ecf0f1;
    cursor: pointer;
    box-sizing: border-box;
}

Below is an image of where I included the code in my child theme (notice the file too):

yNdrDLb.png

And this is how it looks. I have the comments disabled but comments would appear below them (I think).

tyzyQXe.png

I've sunk enough time into this... learning experience... for one night but I may revisit this later to procrastinate on a harder problem that comes up. If any of you fellas have the email part figured out or other platforms, please hook us up. Keep grinding.

tumblr_nal9o2PalZ1rp00pho1_250.gif
 
I'm just laying down, but your question has got me thinking. Have you tried to find any plugins related to what you are looking for and break down their code for how they accomplish it. Like going to Appearance > Editor to edit core Theme files, you can go to Plugins > Editor to edit different plugin files. Of course, you could just download the files without viewing them in your WordPress install if you would rather not install an extra plugin on your site too.

I'll have to look into my viral news theme to see if I can help you out with the Email code.
 
I haven't. Honestly I don't even know the pros and cons of your method. Coding is my weakest area and I'm working to get better. When I started playing with this it was just hard enough to keep me somewhat successful, motivated, and challenged so I started running with it.
 
That's great motivation to continue learning. And knowing just enough to be able to tell someone else or be able to check their work if you choose to outsource it in the future is what it's all about.

I'm just getting to work now but when I get home I'll see if I can't get the email portion of the code for you!
 
Back