Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 5 Connect Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Add Popular Share Buttons (Facebook/Twitter/Etc...) to VB5 without Mods or Templates
BirdOPrey5's Avatar
BirdOPrey5
Join Date: Jun 2008
Posts: 10,610

The details of my life are quite inconsequential.

New York
Show Printable Version Email this Page Subscription
BirdOPrey5 BirdOPrey5 is offline 03-02-2014, 11:00 PM

Note: You must be logged in as a licensed customer to vBulletin.org to see the code & full size screenshots below.

This option was first conceived as a way to allow vBCloud users the ability to get Facebook, Twitter, Google+ and other social media sharing buttons on their sites. vBCloud does not allow access to templates or 3rd party modifications for security reasons so using the existing mods were out of the question.

Despite being created with vBCloud users in mind there is no reason this could not be used by any vBulletin 5 customer, cloud or not.

The final product will look like this- you will need to choose a custom color for your site, I'm using a sky blue:

You can see the live demo at http://sedona.vbulletin.net.



The trick to this is to use the Header's Ad Location template to hold the HTML and JavaScript code needed for the various buttons, and then do some basic styling with inline CSS.

To start make sure Site Editor is enabled and click on the Header button at the top of VB5.

Make sure one header ad is selected and click the Edit button as shown below:



Then click the button to Add New Ad.

You will now be on the screen below:



Enter a title like: Share Buttons

In the larger white box below the title goes the main code. Copy and paste in the following code-

Code:
<div align="left" style="background-color: rgb(102, 140, 202); width:100%; text-align:left; height: 25px;">
<div style="float:left; position:relative; top:2px; left:2px;">
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-layout="button_count" data-action="like" data-show-faces="false" data-share="true"></div>
</div>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<div style="float:left; position:relative; top:2px; padding-left:30px;">
<a href="https://twitter.com/share" class="twitter-share-button" data-via="" date-via="vBulletin" data-lang="en">Tweet</a>
</div>
<div style="float:left; position:relative; top:2px; padding-right: 30px;">
<a href="https://twitter.com/BirdOPrey5" class="twitter-follow-button" data-show-count="false">Follow @BirdOPrey5</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>

<div style="float:left; position:relative; top:2px;">
<!-- Place this tag where you want the +1 button to render. -->
<div class="g-plusone" data-size="medium"></div>
</div>

<!-- Place this tag after the last +1 button tag. -->
<script type="text/javascript">
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/platform.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script>
</div>
Please note that the code in red should be customized before you save the ad.

I will explain what each code is for below-
  • rgb(102, 140, 202) - This is the background color of the entire div- it spans the full width of the document and should be a color that either blends into your header graphic (like mine does) or a perhaps another color used on your page. It is of course up to you.
  • date-via="vBulletin" - This should be Your Twitter Account username. If you don't have a twitter username you can leave vBulletin or just leave it blank. Tweets created using the Tweet button will automatically have the "via" username attached- however the user has the option of deleting this before making the tweet.
  • BirdOPrey5 (2 instances) - These also should be changed to your Twitter Username. A "Follow" button will appear allowing users to easily follow you by clicking on the button. If you prefer to have no follow button you can find the following code:
Code:
<div style="float:left; position:relative; top:2px; padding-right: 30px;">
<a href="https://twitter.com/BirdOPrey5" class="twitter-follow-button" data-show-count="false">Follow @BirdOPrey5</a>
Then edit just the first line of the above code so it says:
Code:
<div style="float:left; position:relative; top:2px; padding-right: 30px; display:none;">
That will hide the follow button but still allow the Tweet button to work.

Then that is pretty much it. Save the ad, make sure it is active, and save all changes.

You will have your own share buttons without the need for any 3rd party mods.

Some addition code you can put in the ad location above is -

Code:
<div style="display:none;"><img src="http://juotpics.com/pics/images/756ss_sedona_bellrock_flo.jpg" /></div>
This is a hidden image, no one will see it load but Facebook will know it is there and use it as the image when someone shares your page.

Change the image URL in Red to the URL of the image you want Facebook to show.

Important - This image cannot be an attachment on your cloud or any other vBulletin site- this must be a real JPG, PNG, or GIF image and the URL must end in one of those extensions. If you do not have anywhere to host the image you can use a free image host like http://tinypic.com.

Facebook needs an image at least 200px x 200px in size. The image should be close to or perfectly square. An 800px x 800px or larger image would be ideal.

You can add multiple lines to give Facebook multiple choices for the image.

Any other images included on pages (such as in posts) may also get picked up by Facebook. Images in posts must be real images using the [img] bbcode, not attachments.
Attached Images
File Type: jpg vb5-share-buttons-no-mods-article.jpg (54.2 KB, 0 views)
File Type: jpg vb5-share-buttons-howto1.jpg (55.9 KB, 0 views)
File Type: jpg vb5-share-buttons-howto2.jpg (65.8 KB, 0 views)
Reply With Quote
  #2  
Old 09-09-2014, 05:33 PM
classicrv classicrv is offline
 
Join Date: Mar 2014
Location: Michigan
Posts: 6
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Working well on 5.1.4. This is a great add on!! Thank you!!

www.classicrv.net
Reply With Quote
  #3  
Old 12-08-2020, 12:25 PM
tahir436 tahir436 is offline
 
Join Date: Dec 2013
Posts: 35
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by BirdOPrey5 View Post
Note: You must be logged in as a licensed customer to vBulletin.org to see the code & full size screenshots below.

This option was first conceived as a way to allow vBCloud users the ability to get Facebook, Twitter, Google+ and other social media sharing buttons on their sites. vBCloud does not allow access to templates or 3rd party modifications for security reasons so using the existing mods were out of the question.

Despite being created with vBCloud users in mind there is no reason this could not be used by any vBulletin 5 customer, cloud or not.

The final product will look like this- you will need to choose a custom color for your site, I'm using a sky blue:

You can see the live demo at http://sedona.vbulletin.net.



The trick to this is to use the Header's Ad Location template to hold the HTML and JavaScript code needed for the various buttons, and then do some basic styling with inline CSS.

To start make sure Site Editor is enabled and click on the Header button at the top of VB5.

Make sure one header ad is selected and click the Edit button as shown below:



Then click the button to Add New Ad.

You will now be on the screen below:



Enter a title like: Share Buttons

In the larger white box below the title goes the main code. Copy and paste in the following code-

Code:
<div align="left" style="background-color: rgb(102, 140, 202); width:100%; text-align:left; height: 25px;">
<div style="float:left; position:relative; top:2px; left:2px;">
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-layout="button_count" data-action="like" data-show-faces="false" data-share="true"></div>
</div>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<div style="float:left; position:relative; top:2px; padding-left:30px;">
<a href="https://twitter.com/share" class="twitter-share-button" data-via="" date-via="vBulletin" data-lang="en">Tweet</a>
</div>
<div style="float:left; position:relative; top:2px; padding-right: 30px;">
<a href="https://twitter.com/BirdOPrey5" class="twitter-follow-button" data-show-count="false">Follow @BirdOPrey5</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>

<div style="float:left; position:relative; top:2px;">
<!-- Place this tag where you want the +1 button to render. -->
<div class="g-plusone" data-size="medium"></div>
</div>

<!-- Place this tag after the last +1 button tag. -->
<script type="text/javascript">
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/platform.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script>
</div>
Please note that the code in red should be customized before you save the ad.

I will explain what each code is for below-
  • rgb(102, 140, 202) - This is the background color of the entire div- it spans the full width of the document and should be a color that either blends into your header graphic (like mine does) or a perhaps another color used on your page. It is of course up to you.
  • date-via="vBulletin" - This should be Your Twitter Account username. If you don't have a twitter username you can leave vBulletin or just leave it blank. Tweets created using the Tweet button will automatically have the "via" username attached- however the user has the option of deleting this before making the tweet.
  • BirdOPrey5 (2 instances) - These also should be changed to your Twitter Username. A "Follow" button will appear allowing users to easily follow you by clicking on the button. If you prefer to have no follow button you can find the following code:
Code:
<div style="float:left; position:relative; top:2px; padding-right: 30px;">
<a href="https://twitter.com/BirdOPrey5" class="twitter-follow-button" data-show-count="false">Follow @BirdOPrey5</a>
Then edit just the first line of the above code so it says:
Code:
<div style="float:left; position:relative; top:2px; padding-right: 30px; display:none;">
That will hide the follow button but still allow the Tweet button to work.

Then that is pretty much it. Save the ad, make sure it is active, and save all changes.

You will have your own share buttons without the need for any 3rd party mods.

Some addition code you can put in the ad location above is -

Code:
<div style="display:none;"><img src="http://juotpics.com/pics/images/756ss_sedona_bellrock_flo.jpg" /></div>
This is a hidden image, no one will see it load but Facebook will know it is there and use it as the image when someone shares your page.

Change the image URL in Red to the URL of the image you want Facebook to show.

Important - This image cannot be an attachment on your cloud or any other vBulletin site- this must be a real JPG, PNG, or GIF image and the URL must end in one of those extensions. If you do not have anywhere to host the image you can use a free image host like http://tinypic.com.

Facebook needs an image at least 200px x 200px in size. The image should be close to or perfectly square. An 800px x 800px or larger image would be ideal.

You can add multiple lines to give Facebook multiple choices for the image.

Any other images included on pages (such as in posts) may also get picked up by Facebook. Images in posts must be real images using the [img] bbcode, not attachments.

Thanks for this beautiful MOD. When I click on the edit button in the header section I recieve a pop up window saying: Error information: " 0 error "

Any fix for this?

Thanks
Reply With Quote
  #4  
Old 12-11-2020, 09:19 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That would seem a bug with the vBulletin software, not the code in this article. I don't have a fix.
Reply With Quote
  #5  
Old 09-21-2023, 03:01 PM
mdawg's Avatar
mdawg mdawg is offline
 
Join Date: Mar 2009
Location: United States
Posts: 363
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I disabled the related Mod:
https://vborg.vbsupport.ru/showthread.php?t=287907
because it doesn't seem to work any long, at least not the Facebook "Like" button on vb 5.7.5
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:12 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04384 seconds
  • Memory Usage 2,290KB
  • Queries Executed 21 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (8)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (2)post_thanks_box_bit
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (5)post_thanks_postbit_info
  • (4)postbit
  • (3)postbit_attachment
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete