Trouble Adding AdSense Code for Page-Level Ads? Learn how to fix it.

In order to add the Page-Level ads functionality from AdSense on your Blogger blog you are required to place a code that AdSense provides which is :

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"/>

Unfortunately if you have tried placing the code in your theme you may have run into this error that states:

Error parsing XML, line n, column n: Attribute name "async" associated with an element type "script" must be followed by the ' = ' character.



That's a bit annoying - What could be going wrong with the code that AdSense (a Google product) has provided is causing error on Blogger (another Google product).

The problem is highlighted in the error message itself "Attribute name "async" associated with an element type "script" must be followed by the ' = ' character."

Attribute name "async" in the code we got must be followed by a '=' character. But the code we got simply has <script async  ... />

So what can be done? Modify the code to be parsed by Blogger's theme parser correctly. Here's the code with a little change, we replaced async with async="async" to make the code a valid XHTML markup.

<script async="async" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

Place this code in your Blogger theme code and save. It should work properly now.

Why do we have to use this "hack"?

This shouldn't even be considered as a hack. This is plainly a case where a valud HTML5 markup is not parsed as a valid XML / XHTML markup. 

Yes, our blogs are HTML5 in the end when it gets loaded on a web browser, but the code that runs in the background is XHTML, and the thing with XHTML is that it is very strict about the markup language. In HTML5 you can simply leave out a value from a attribute or leave an HTML element unclosed and it will still work. 

But XHTML won't. What's valid in XHTML is also valid in HTML5, so this don't need to be considered a hack or even a workaround. AdSense provides the code that is totally HTML5 compliant only it didn't anticipate the case where users may want to add the code to XHTML templates.

Will it have any impact on the way this code is supposed to work?

Other than having a few extra characters in the code you had to add, no. This change wouldn't affect anything how AdSense is supposed to work. We just made the code compliant with XHTML to be taken in by Blogger.



Inviting All Friends to Facebook Page at Once JavaScript Snippet

Facebook is a great tool for connecting with the World but one of the problem is that the population on Facebook is very big and so sometimes we feel the need of a "do all" function in most places such as inviting your friends on your new page.

It can be a hefty job clicking on thousands of "Invite" buttons one after one since Facebook doesn't give you an "Invite all" button. Same used to be true for Group requests but fortunately it now does, but as for Facebook page invites you still have to do the manual way.


In this tutorial we will be learning how to invite all friends to page on Facebook automatically. In the past on our blog we posted some similar codes for Facebook but as you know Facebook changes it design and structure so not all the old codes may still work.

This one is latest and is working (created in June 2017).

We will keep this short, there's only two step mainly, copy the code and paste it, but to perform it successfully we have to do more than just that.

Copy the JavaScript Code 


var btns = document.querySelectorAll("button");
var i = 0;

setInterval(function(){
if ( btns[i].textContent == "Invite" ) {
btns[i].click();
console.log( i + " buttons clicked." );
}
i++;
}, 200);

Open Facebook on Desktop in Chrome / Mozilla Firefox or Safari

After you've open the Facebook website, navigate to your page and you will see the section where you can invite your friends from.


Click on "See All Friends" to make sure all your friends are loaded in the invite section so that when we run the code it invites all of them.  

In the browser open JavaScript Console and Paste the Code

Browsers have a JavaScript console where you can run JavaScript code from on the page, to open it on different browsers see the instructions :

  • Google Chrome: CTRL+Shift+J (CMD for Mac) OR Right click on page > Inspect > Console tab
  • Safari: Safari > Preferences, click Advanced, then select “Show Develop menu in menu bar.”. Now in the Safari Develop menu select "Show JavaScript Console"
  • Firefox: CTRL+Shift+J (or CMD+Shift+J on a Mac) ORselect "Browser Console" from the Web Developer submenu in the Firefox Menu (or Tools menu if you display the menu bar or are on OS X)




Paste the code in the input area in the Console section and then hit enter. 

That's it, the code will start running and will automatically invite all the friends to your Facebook page in no time. 

Does it have a limit?

There's no limit set by the code, it can invite any numbers of people in very less time but Facebook has a limit on how many friends you can invite to a page daily. Once it exceeds you won't be able to invite friends on the same day. 

We respect that and everyone should, Facebook knows that spamming would be a lot easier for people if it doesn't put such restrictions. 

Please do not use the code for spamming purposes, this tutorial is meant for the people who are genuinely inviting their friends on their page. There's no risk of getting blocked by using this method but we cannot be sure if it is abused, the system will detect. 

Why shouldn't I use an extension?

There are many extensions and add-on in browsers that lets you do the same but our recommendation is that you do not use those and the simple reasons are
  1. You never know what the extension might be running in the background
  2. Such extensions are known to go rogue and show pop-up ads in the future
  3. Do you really need to install a forever running extension for a small task ?
Using the codes you know what you are running on your Facebook pages, because running scripts is very sensitive in browsers, scripts can be used to do a lot of harmful stuffs, so always double-check before running any extensions or scripts in your browser. 

I see an error

Don't worry, it happens, even a small typo can lead to an error. If you see any error commend down below with a screenshot so we can jump in to help you in that regard. 


Full Sized Background Image on Blogger with Blur Effect

In this short tutorial you will learn how to add an image as the background of your blog that stretches to all edges thus fills your entire blog's background portion.


Looking to add a nice effect to your blog by using beautiful pictures as background images? It is a great way to personalize a blog, depending on the color scheme of your blog and the feel that you want the blog to have can all be improved by using an image as the full background.



This tutorial will be guiding you through the process of setting a custom full size image on your Blogger blog with a few lines of CSS as well as showing a way to give it a blurred glass effect.

Here's a quick demo of what you are going to have on your blog by following the steps to add the CSS to your blog: Full Page Background Image Blurred Effect using CSS

Uploading the image

Whatever image you are going to use you have to upload it somewhere in its full size first. The best place to upload it is Blogger itself, it gives unlimited photo storage as well as fast servers from Google wouldn't ever slow your blog down. 

  1. Open a draft post in your Blogger dashboard
  2. Upload the image
  3. When the image appears in the post area, right click on it and "Copy image address" or "Copy link address", the option might be different on different browsers.
  4. Paste the copied URL that is the image's address in a Notepad / Textedit app. We may get something like this

    https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyrajfadQBUo8BooKtb2RHwsSG3DsiDCrVtBHEkAVqP6zcdTmtcmXJ3XQiBo1B0WO6AaeyLOljOpRaaaabRAbD4Y0jnfBmq6pY9TZrb9z0v7pIaWucvuvajBbg2KiWedjLR5pDoqAC9xy2/s1600/photo-1434394673726-e8232a5903b4.jpg
  5. Keep it with yourself, we will need this in the next step. 

The CSS Snippet

CSS is what makes it possible for us to add designs to our websites and blog. This one does the job for adding a full screen background.

html, body {
background: url('IMAGE-URL-HERE') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}

Copy the CSS code and paste it in another Notepad / Textedit window.

In this code, replace IMAGE-URL-HERE with the image URL we got in the last step.

html, body {
background: url('https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyrajfadQBUo8BooKtb2RHwsSG3DsiDCrVtBHEkAVqP6zcdTmtcmXJ3XQiBo1B0WO6AaeyLOljOpRaaaabRAbD4Y0jnfBmq6pY9TZrb9z0v7pIaWucvuvajBbg2KiWedjLR5pDoqAC9xy2/s1600/photo-1434394673726-e8232a5903b4.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}

I've done it, what now? Now that you have placed your image's URL in the code we are ready to make it appear on the blog. but before that please do take a backup of your existing blog theme.

  1. Log-into your Blogger Dashboard
  2. Go to the Theme   section
  3. Click on "Customize" 
  4. In the Theme Designer go to Advanced > Add CSS
  5. Paste the CSS snippet into the text area on the theme designer page and click on Apply to Blog on the top right
Open your blog to see the updated background image. Right now you wouldn't see the blur effect, we will see how to do that in the next step.

Let's give it a blurred effect


We assume you are still in the Advanced > Add CSS page in the Theme designer from the last step. A small change in the URL of the image is required to get the blurred effect - that is to reduce the size of the image. Yes, the smaller the image the more blurry it will be. So that's our general idea, instead of using a photo editor app to make the original image blurry we use a small version of the original image.

Let's suppose your code is this, the URL of your image is of course different than the one in the following one.

html, body {
background: url('https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyrajfadQBUo8BooKtb2RHwsSG3DsiDCrVtBHEkAVqP6zcdTmtcmXJ3XQiBo1B0WO6AaeyLOljOpRaaaabRAbD4Y0jnfBmq6pY9TZrb9z0v7pIaWucvuvajBbg2KiWedjLR5pDoqAC9xy2/s1600/photo-1434394673726-e8232a5903b4.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}

In the URL of your image, which may look something similar to this:

https://3.bp.blogspot.com/..............ynOTNfQCKgB/s1600/photo-1434394673726-e8232a5903b4.jpg

Change the number with the s prefixed to it to something smaller.

https://3.bp.blogspot.com/..............ynOTNfQCKgB/s32/photo-1434394673726-e8232a5903b4.jpg

s32 means the CSS code will load a version of the image that is only 32 pixels wide, so when a small image stretches from edge to edge on a screen it becomes blurry and gives the perfect effect we want.

You can change the value to whatever you like to adjust the level of blurriness of your background image. Change that small part in the code and again click on Apply to Blog to update the CSS code and make it go live on your blog.

Help Needed?

On some third-party themes and even the original themes provided by Blogger the code may not work properly due to some other CSS setting that may be overriding it. If you are unable to get it working then please share your blog URL in the comments down below along with the code that you are using as it is. We would be glad to jump in to help.


Full Blog Posts on Notable Theme's Homepage in Blogger Blogs

In the new themes the page break in post editor is just for the name as the themes auto-truncates the posts and shows snippets and a preview thumbnails only on the homepage. Page break / Jump break is good only for feeds now.

There is no setting to make the theme show full posts on the home, index and archive pages and that is why we feel the need of writing this tutorial.


Previously on StramaXon we published a tutorial to show how it was done on Contempo theme, this tutorial will guide you through the steps to achieve the same with Notable theme, so if you are a Notable Theme user in Blogger then follow the steps given below to get your blog posts to show up as full.

Important: As with all of our tutorials where we are supposed to touch the theme code it is highly recommended that you take a backup of your current Blogger theme.

Video walk-through. 

We've prepared a video tutorial of the same so you can watch it and follow the steps with more ease. 

Link to the video tutorial.



Editing the XML / HTML Code in Theme

  1. Open a new tab in the browser and Log-into your Blogger Dashboard
  2. Go to the Theme   section
  3. Click on "Edit HTML"
  4. When the Theme code editor opens, focus into the code editor and hit CTRL + F / CMD + F to open the in-page search
  5. Look for the following line of code|

    <b:include cond='data:this.postDisplay.showSnippet ?: true' data='post' name='postBodySnippet'/>

  6. Upon searching you will get the result like this,



  7.  Copy the following HTML / XML markup

    <b:if cond='data:widget.type != &quot;PopularPosts&quot;'>
    <div class='post-body-container'>
    <b:include data='post' name='postBody'/>
    <div class='post-sidebar invisible'>
    <b:with value='data:widget.instanceId + &quot;-normalpostsidebar-&quot; + data:post.id' var='sharingId'>
    <b:include cond='data:post.shareUrl' data='{ shareButtonClass: &quot;post-share-buttons-top&quot;, overridden: true }' name='maybeAddShareButtons'/>
    </b:with>
    <b:if cond='data:post.labels and !data:post.labels.empty and data:this.allBylineItems.labels'>
    <div class='post-labels-sidebar'>
    <h3><data:messages.labels/></h3>
    <b:include data='post' name='postLabels'/>
    </div>
    </b:if>
    </div>
    </div>
    <b:else/>
    <b:include cond='data:this.postDisplay.showSnippet ?: true' data='post' name='postBodySnippet'/>
    </b:if>

  8. Go back to the theme editor where we previously found the line of code from step 5. Replace that line of code with the code you just copied. This is what it the XML code should look like when you have replaced it.


  9. Now click on "Save theme" to save the changes and go to your blog to see the change. The posts should now appear full on all the pages. 

You may have noticed that the "Read More" button is still there even though the post shows up full, it's because the Jump link is added by another code that we didn't touch yet and it isn't even necessary, we will be using CSS to simply hide the links.

CSS to hide the Jump Link

This CSS snippet should hide the "Read more" links from the posts on home, archive and index pages.
.widget.Blog .jump-link {
    display: none;
}

Here's a complete guide with screenshots on adding CSS in Blogger blogs

  1. Log-into your Blogger Dashboard
  2. Go to the Theme   section
  3. Click on "Customize" 
  4. In the Theme Designer go to Advanced > Add CSS
  5. Paste the CSS snippet into the text area on the theme designer page and click on "Apply to Blog" on the top right
Refresh your blog to see the changes live on your blog.

Showing full blog posts on other new themes

The same can be done on other themes and here are the links for the tutorial to do it on other new Blogger theme(s)


Semi-Transparent Header on Blogger's Notable Theme

The header on the Notable theme in Blogger sticks to the top when you are scrolling down, that's a neat design and good thing for mobile users who may otherwise find it difficult to scroll all the way up to access the navigation menu.

In this post we will use a small CSS snippet that let's you make the header semi-transparent or in simple words a see-through navigation menu. You can set the opacity yourself to fit your needs since you may want it to be less or more opaque. 


Our posts are known to stretch a little bit too much so we are going to keep this short because there's not even much to it. There's a CSS snippet that you add to your blog's theme, that's all. 

The CSS we will need. Note that this is for the Notable Blogger Theme, this may or may not work with other themes. 

header.centered-top-container.sticky {
opacity: 0.8 !important;
}

The value 0.8 is the opacity of the header, it can be anywhere from 0 to 1.0, setting it 0 will cause the header to be completely transparent so we do not want that. You may change the value to your needs and then add it to your blogger.

How to add the CSS code?


  1. Log-into your Blogger Dashboard
  2. Go to the Theme   section
  3. Click on "Customize" 
  4. In the Theme Designer go to Advanced > Add CSS
  5. Paste the CSS snippet into the text area on the theme designer page and click on "Apply to Blog" on the top right
That's done. Now refresh your blog to see the changes. 

If you have request for tutorials for other Blogger themes then please do comment below. 

Automatically Place AdSense Ads After Jump Breaks in Blogger Blog Posts

The placement of ads on a website is a very important aspect to maximize the revenue from ads on your blog. Ads placed inside of articles in a standard way i.e in a way that the user can distinguish between the content and the ad is very effective.

In this tutorial we will go through the steps to set-up the blog in a way that an AdSense ad block is automatically added after the page break in a post.



For a demo you can take a look at our blog post, an ad is just right below the last paragraph (it is where we added the page break for this post). It is important for a page-break to exist in the post for this tutorial to be effective.

We assume you add page breaks or more commonly called jump breaks in Blogger, in your blog posts.

Getting started with the tutorial

We are going to make changes to the template code in order to add this functionality so we suggest you to make a backup of your blogger template before proceeding. Check this tutorial on backing up a blogger template

Adding the Google AdSense Script. 

You may have noticed that you the AdSense script is given with all of your AdSense Ad snippet though AdSense implementation guide tells us that only loading it once is sufficient enough for all ads to work. 

The script that we are talking about is wrapped in this line of code, you may have noticed it several times if you have worked with AdSense codes which we assume you have. 

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

We will be adding this script in the head of the blog's template so that our automatically added ad works properly.

  1. Open your Blogger Dashboard > go to the Theme section
  2. Click on Edit HTML button for the template's code show up
  3. When you are in the template code editor, hit CTRL+F / CMD+F to open search box and search for </head>
  4. Copy the following line of code and paste it immediately above </head&gt;

    <script async="async" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

  5. It should be something like this :



    Finally click on Save theme

Preparing the Ad Slot 

Next task is to prepare the code that we will be inserting into the blog post after jump break. It is suggested that you use a responsive ad unit because that works the best on even mobile devices, still you are free to choose any that you like, the choice makes no difference. 

Create your Ad unit in AdSense and click on "Get code", you will get the ad code which should look something like : 

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- My Responsive Ad Unit  -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-xxxxxxxxxxxxxxxx"
     data-ad-slot="xxxxxxxxxx"
     data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

Now, we do not need all of that, only the part that is highlighted i.e line 3, 4, 5, 6 and 7. Open up a notepad / textEdit window and paste your ad code and remove the excess code. You will be now left with:

<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-xxxxxxxxxxxxxxxx"
     data-ad-slot="xxxxxxxxxx"
     data-ad-format="auto"></ins>

Finally, we now have to edit this code a little bit that is to remove the line breaks in the code, we will be putting this code inside of a JavaScript code as a string so we need it to be without line breaks. Simply use a text editor and remove the line breaks, so the final code would look like this -

<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-xxxxxxxxxxxxxxxx" data-ad-slot="xxxxxxxxxx" data-ad-format="auto"></ins>

All on only one line, that is what we need. Keep this code with you, in the next step (which is the final, that's a promise) we are going to need it because it is what we will be inserting using JavaScript code.

Adding the main JavaScript Script for making this work

The last steps may have been a lot tedious, we can understand, but we are almost done, just a few more steps.

This following script is what we need to actually insert our ad unit's code inside of the blog post after jump breaks automatically.

<script type="text/javascript">
// <![CDATA[

document.addEventListener('DOMContentLoaded', function(){
// we look for the jump break
var _moreElm = document.querySelector('a[name=more]');

// here is your adsense code
var _adsenseCode = ' [replace this with code from the last step] ';

// This inserts the ad inside of the blog post
_moreElm.insertAdjacentHTML(
'afterend',
'<div class="adsense-after-break">' + _adsenseCode + '</div>'
);

// Initialize the ads here
(adsbygoogle = window.adsbygoogle || []).push({});
});

// ]]>
</script>


For now copy and paste this into your text editor. There's only one single line that you have to change so that this code works. That is the line 9 (highlighted in the code)

var _adsenseCode = ' [replace this with code from the last step] ';

Delete [replace this with code from the last step] and paste the ad unit code from the last section so it looks like this

var _adsenseCode = ' <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-xxxxxxxxxxxxxxxx" data-ad-slot="xxxxxxxxxx" data-ad-format="auto"></ins> ';

After you've made the necessary changes as explained above we are all set to include it in the theme code. Follow the steps below
  1. Go to Blogger Dashboard > Theme section
  2. click on Edit HTML
  3. In the template code editor hit CTRL+F / CMD+F and search for </body>
  4. Paste the code we have immediately above </body> and save the theme. The code would look something like this when in place

     
That's it! You've done it. Now reload your blog and go to a blog post to see the ad appear automatically in your blog post. 

In case it doesn't seem to work then make sure
  • that you have JavaScript enabled and there is no ad blocker enabled. 
  • that you have a jump break in your post
  • that your ad unit is active. New ad units may take some time to start showing ad. 

Bonus: A little styling

The following CSS will add margins around the ad unit and also a border for users to visually distinguish between the content and the ad.

.adsense-after-break {
/* margin and the padding */
margin: 0.5em 0;
padding: 0.5em;
/* Center align */
text-align: center;

/* Following styles the border */
border: 1px dashed #ccc;
border-width: 1px 0;
}

Copy the CSS code above and then add it to your blogger theme.


We hope you find this tutorial helpful. If you have questions / suggestions or feedback feel free to comment down below. 

FancyBox 3 Image Lightbox & Slider for Blogger.com Blogs

Lot of us posts photos on our blogs daily and being able to view it in light box / gallery view is a basic function for every blog and Blogger does provide one but one that is very old and needs an upgrade so we have decided to post this tutorial to help you add FancyBox 3 in your blogger blog.


FancyBox 3 is an image / content light-box plugin that provides the feel of a modern and responsive website. If you have had experience with the Blogger's default light-box feature you may have felt that it is very basic and for a blog that focuses more on photos and images it might not be the best option.

Demo & Comparison

For example, here we have two photos, the first one is set to open in Blogger's default light-box and the other is the FancyBox light-box plugin.

Here's a demo on a test blog - Demo for Image Lightbox 

Images with Blogger's Default Lightbox


  

Images with FancyBox 3 Lightbox

  


The jQuery plugin, FancyBox plugin is more than just a image lightbox / gallery, it can do a lot more than just images but in the Blogger environment we will be just focusing on images because that is what we need here.

Here are a few attractive features of the FancyBox plugin -

  1. Modern design and feel
  2. Responsive and touch enabled, works flawlessly on mobile devices. 
  3. Full screen and zoom option
  4. Slideshow option for multiple images in a gallery (i.e a post in Blogger blogs)
  5. Very flexible - if you know basic HTML / JavaScript you can do a lot more with this plugin. 

Setting it up

Note: Before starting consider taking a backup of your current Blogger template

The FancyBox 3 plugin is a jQuery based plugin and for it to work jQuery needs to be added to your template as well though many templates (most likely if it is a third-party template or you have previously added such plugins) may already have jQuery added into it and it is not recommended to add it again as that just makes the page load the same thing twice which is not good for the performance of a website. 

Check if you already have jQuery:

In this tutorial we will be asking you to add certain script files required for the plugin to work, jQuery code too, though if you already have it on your blog then avoid adding it again is the best option.

To check whether you have jQuery or not follow these steps -

  1. Go to your Blogger Dashboard > Themes
  2. click on Edit HTML 
  3. open in-page search CTRL+F/CMD+F and enter the keyword "jquery"
  4. Does it take you to a line with "<script src='.../jquery.min.js' " (may look similar) ? If yes then you already have jQuery
  5. And if not then you do not have it, so in the next steps be sure not to omit the jQuery script. 

Adding the scripts and stylesheets

The Fancybox plugin is a lightweight jQuery plugin with a lot of functionalities. It depends on jQuery to work, and a stylesheet that tells the browser how to display things under it, in total there are 3 files we will be adding, namely - jQuery, FancyBox Script and FancyBox Stylesheet. 

Note: If you already have jQuery in your template it is recommended you remove the line from the following HTML markup that adds the jQuery script. 


Copy the following HTML snippet, 

<!-- FancyBox CSS -->
<link href="//cdnjs.cloudflare.com/ajax/libs/fancybox/3.0.47/jquery.fancybox.min.css" rel="stylesheet" type="text/css"/>

<!-- jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- FancyBox 3 -->
<script src="//cdnjs.cloudflare.com/ajax/libs/fancybox/3.0.47/jquery.fancybox.min.js"></script>

Upon copying paste it in a Notepad / TextEdit application. When you have the code snippet in a text editor remove the line with <!-- jQuery --> and the line after that if you found that jQuery already exists in your template, else keep the whole code without making any changes. 

To add it in the template, 
  1. Go to your Blogger Dashboard > Theme
  2. Click on the Edit HTML button on the page
  3. search for </body> 
  4. Paste the code immediately above the </body> tag
  5. Save the theme.

The </body> tag is basically the end of the body of the page and that is where we are adding the scripts because such scripts are run only when the complete HTML has been loaded. 

In case you already had jQuery in your template and you deleted the jQuery from our code then do remember that these scripts should always come after the jQuery's script, adding them before it may result in error. This is a common mistake people make, and confirming this can save you a lot of time in figuring out what went wrong.

Disable Blogger's Lightbox

The codes we added in the previous section has no effect on your images now and that's normal, we haven't initialized the scripts so you wouldn't be able to open it using FancyBox lightbox plugin as for now, we will be doing that shortly, but before that make sure you turn off Blogger's default image lightbox as it may conflict with the one we've added.

  1. Go to your Blogger Dashboard
  2. Settings > Posts, comments and sharing settings
  3. Next to "Showcase images with Lightbox" choose "No" from the dropdown list. 
  4. click on the "Save settings" button on the top right of the page.
Great, now the lightbox from Blogger is disabled and we can continue on activating our new lightbox plugin. 

Activating the plugin on photos / images

Without specifying which images is to be activated in lightbox we assume that all images inside of the post body that has links to an image is supposed to open in the lightbox. 

It is important for us to tell the plugin that "Hey, don't have effect on images outside of the post body" that's because there are many images all over the blog that you don't want to be opened in the lightbox so we isolate the plugin within the post body. 

Copy the following code,

<script type="text/javascript">
//<![CDATA[
$(document).ready(function(){
/**************************
This part makes sure we select only the images and photos that is supposed to appear in a lightbox
**************************/
$(".post-body a img").each(function(){
var isImage = /\.(?:jpg|jpeg|gif|png)$/i.test( $(this).parent("a").attr("href") );

if ( isImage ) {
$(this).parent("a").attr('data-src', $(this).parent("a").attr("href"));
$(this).parent("a").attr('data-fancybox', 'postLightBox' );
}

else {
// .. do nothing
}
});


/**************************
This part initializes FancyBox on the qualifying images
**************************/
var options = {
infobar : true,
buttons : true,
speed : 300, // Animation duration in ms
margin : [40, 20] // Space around image, ignored if zoomed-in or viewport smaller than 800px
};

$("[data-fancybox]").fancybox( options );
});
//]]>
</script>

You have to add this code after the line of code we added in the "Adding the scripts and stylesheets" part of the tutorial.
  1. Go to your Blogger Dashboard > Theme
  2. Click on the Edit HTML button on the page
  3. search for </body> 
  4. Paste the code immediately above the </body> tag 
  5. Save the theme.

It's time to test it! After saving the theme open up your blog and go to a post with images and click on the image and it should now be opened in the new modern light box rather than the old one Blogger provides initially.

Have questions? 

You might have questions about the plugin or something about it that isn't working as you expected, we've put down some common questions and its answers for you - 

Is FancyBox safe to use?

Yes, it is one of the most popular jQuery plugin for content lightbox on the web and it is used by hundreds of thousands of websites. 

Learn more about it on FancyBox's homepage.

Would it work in the new Blogger themes?

Yes, it is supposed to work perfectly in the newer themes. If you are facing issues with any theme please comment down below with your blog URL and we will take a look.

As for third-party customized themes we cannot guarantee.

How can I make it work only on the images I want it to?

The part $(".post-body a img").each(function(){ in the code that activates tells the plugin which images to choose and by default it activates on all images inside of a post body. 

If you want it to work only on certain images and not all then follow these steps 
  1. Open your blog post in the post editor and click on the HTML button next to the Compose button 
  2. When you are in the HTML mode, look for the image's code which might be something like

    <a href="[.....]"><img src=" [.....] "/></a>

    To the <a> tag add a specific class name value to it, for e.g

    <a class="lightbox-image" href="[.....]"><img src="[.....]"/></a>

    You can notice we added class="lightbox-image" to the <a> element.
  3. In the JavaScript snippets change

    $(".post-body a img").each(function(){

    to

    $("a.lightbox-image").each(function(){

    And save it to the template code.
Now images which is inside an anchor link i.e <a> tag that has a class name that you defined, here we used "lightbox-image" (you can use anything else that starts with an underscore or an alphabet).

I would like to add captions to my lightbox images, how do I do it?

Caption that you want to appear for a image should be manually added in the source of the image's HTML code. Here's how you can,

  1. Open the post in the post editor and switch to the HTML mode 
  2. Look for an image's HTML code, at minimum it would look like this

    <a href="{image-url}" >
    <img href="{image-url}"  />
    </a>

  3. Add data-caption="Your caption here" to the <a> of the image, e.g

    <a data-caption="This is a caption of the image" href="......." >
    <img href="........"  />
    </a>

  4. Save the post. 
Basic HTML is supported inside of the data-caption attribute, so you can add italic, bold or large text inside of the caption as well.


I want to customize it according to my needs, how do I do it?

If you have a good knowledge of JavaScript, HTML and CSS then you can head over to the plugin's homepage and take a look at the documentation to learn how to customize it - http://fancyapps.com/fancybox/3/

Not everyone is a coder we understand but to customize it according to ones' needs some advanced knowledge is needed. You can hire or ask a web developer / designer to help you out.

If your need is not big and what you want can be achieved by simply modifying a few codes here and there I can provide your free of cost help though in case it requires good amount of time and work I am available for hire as well. You can contact me at depy45631@gmail.com for any help or hiring me for a work.

Anything else?

For feedback, suggestions and requests please comment down below.