Adding Google's "I am feeling Lucky" button feature of choosing a random post on Visitors Demand in Blogger to increase reader Engagement and Pageviews
![]() |
| Google Inspired I am Feeling Lucky button for Blogger |
Instructions to Follow:
Begin by going to your blogger layout section and click on "Add a Gadget" to open the gadget gallery from there choose the HTML/Javascript widget. In the HTML/javascript widget keep the title section empty and add the below code under the content section of the widget.Adding the Lucky HTML:
The Above code will render the "I am Feeling Lucky" placeholder button feature to your blog. You can add it anywhere in the sidebar(preferred) or footer where it's most likely visible to the reader and clicked.<div id="genius-howto"></div>
Now to add in the random functionality to the above html add the below code just above the </body> tag by going to your blogger template → Click Edit HTML → search for </body> tag by using CTRL+F in the template editor and add the below code above it.Adding the Random Post Functionality
In case you wish to change the "I am Feeling Lucky!" (marked above in red) text to something else then change it with your desired slogan in the above script. Be careful not to delete anything else as it will corrupt the script making it nonfunctional.<script>function showLucky(root){ var feed = root.feed; var entries = feed.entry || []; var entry = feed.entry[0]; for (var j = 0; j < entry.link.length; ++j){if (entry.link[j].rel == 'alternate'){window.location = entry.link[j].href;}}} function fetchLuck(luck){ script = document.createElement('script'); script.src = '/feeds/posts/summary?start-index='+luck+'&max-results=1&alt=json-in-script&callback=showLucky'; //copyright by geniushowto.blogspot.com Inc (keep intact) ***************** script.type = 'text/javascript'; document.getElementsByTagName('head')[0].appendChild(script); } function feelingLucky(root){ var feed = root.feed; var total = parseInt(feed.openSearch$totalResults.$t,10); var luckyNumber = Math.floor(Math.random()*total);luckyNumber++; a = document.createElement('a'); a.href = '#random'; a.rel = luckyNumber; a.onclick = function(){fetchLuck(this.rel);}; a.innerHTML = 'I am Feeling Lucky!';document.getElementById('genius-howto').appendChild(a); }</script> <script src="/feeds/posts/summary?max-results=0&alt=json-in-script&callback=feelingLucky"> </script> If you followed above two steps your "I am feeling lucky!" text with functionality will be visible on your blog and to add in the extra pot of luck let's beautify the button with lucky CSS. To add in the CSS go to your blogger template → Click customize → Navigate to Add CSS section under Advanced menu and add in the below CSS into your add custom css section.Beautifying with lucky CSS
#genius-howto{position:relative;color:rgba(0,0,0,1);text-decoration:none;font-family:'Times New Roman';font-size:25px;display:block;box-shadow:0px 0px 0 #000000, 0 9px 25px rgba(0,0,0,.6);margin-bottom:10px;margin-top:10px;width:90%;text-align:center;padding:4px;float:center;} #genius-howto:hover{box-shadow:0 3px 0 #000000, 0 3px 6px rgba(0,0,0,.9);position:relative;top:5px}#genius-howto a{color: #000; text-decoration:none;}
Now you should be able to see your shiny little "I am feeling Lucky" button on your site or blog. Make sure to click apply after adding in the CSS to your template.Now go ahead and text the feature yourself as it directs you to random posts. Quite fun right? In case you don't want to edit a lot or hate codes then use the below method to grab the whole code paste it as widget and enjoy.
Now in case you don't wish to edit your blogs template and simply wish to add it as a gadget then add in the below code to your blogger html/javascript widget. Just go to blogger layout section → Click Add a Widget → Choose HTML/Javascript widget and add the below code as the content and click save.Method-2: Adding the whole functionality as a widget (no template editing required)
Just copy the above code in your html/javascript widget and give your readers a entertaining way to browse your blog and articles.<style>#genius-howto{position:relative;color:rgba(0,0,0,1);text-decoration:none;font-family:'Times New Roman';font-size:25px;display:block;box-shadow:0px 0px 0 #000000, 0 9px 25px rgba(0,0,0,.6);margin-bottom:10px;margin-top:10px;width:90%;text-align:center;padding:4px;float:center;} #genius-howto:hover{box-shadow:0 3px 0 #000000, 0 3px 6px rgba(0,0,0,.9);position:relative;top:5px} #genius-howto a{color: #000; text-decoration:none;}</style> <div id="genius-howto"></div> <script src="http://geniusknight.weebly.com/files/theme/iamfeelinglucky.js"></script> <script src="/feeds/posts/summary?max-results=0&alt=json-in-script&callback=feelingLucky"> </script>
