Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Fix javascript errors (because I don't know how) WordPress


I had someone create me a cool little plugin that allows me to input a CSS element ID and that element will float to the top of the page and stick there when the site is scrolled. Much like the top of Facebook.

It works great on my homepage, my posts, and my pages. But for some reason the javascript doesn't work on my custom post type single template pages.

Examples: (keep your eyes on the three main-menu links at the top as well as the floating social share bar on the side, those are the things that don't work.)

<strong>Working here:</strong> (home page) (regular post single template)

<strong>Not working here:</strong> (custom post type "user_video") (custom post type "event")

The page templates are very similar and do not have any inline scripts which would effect the plugin.

Can anyone take a look and figure out what I need to fix to make this work?

Thanks in advance.

Answers (3)


Giri answers:

Disable wordpress debugging.

Edit wp-config.php

Change this value

define('WP_DEBUG', true);


define('WP_DEBUG', false);

Zac Eckstein comments:

I have debugging on on purpose because I'm developing the site. This is not the issue.

Giri comments:

Ok I got it.. This is happening because your custom post types missing the offset css class.

This is the class that determine css offset.

Pages that has the following code works perfectly.

<span class="wpsr_floatbts_anchor" data-offset="15"></span>

You custom post type missing that code.

You should edit your file just search for that code.

Or edit your post using editor goto html tab.. Add this code in the place where you want the scrolling begin...

<span class="wpsr_floatbts_anchor" data-offset="15"></span>

Zac Eckstein comments:

Thank you. Yes, I had just figured this out as well! Thanks for doing the research.


Luis Abarca answers:

You have some errors on your CPT.

This is how it looks your source code

<script type="text/javascript">
<br />
Notice: Undefined variable: socialbt_processed in /home/seavine/public_html/wordpress2013/wp-content/plugins/wp-socializer/includes/wpsr-socialbuttons.php on line 361<br />
<br />
Notice: Undefined variable: socialbt_processed in /home/seavine/public_html/wordpress2013/wp-content/plugins/wp-socializer/includes/wpsr-socialbuttons.php on line 361<br />

Zac Eckstein comments:

Socialbt is part of a a plugin. Those are just notices so they shouldn't have any effect on anything else. I was told there was javascript errors on my site and I'm trying to figure out what they are and how to fix them.

Luis Abarca comments:

You have javascript errors, "Uncaught TypeError: Cannot read property 'top' of undefined" on wp-socializer-floating-bar-js.js

Looks like a HTML element is missing.

Zac Eckstein comments:

OK. I'm sorry, I really don't understand JS so I'm looking for some actual help on how to solve the problem. What would be helpful, should I post the offending JS file for you to take a look at? Here it is (below).

* Copyright 2013 Aakash Chakravarthy -
* Created for WP Socializer - Wordpress Plugin
* v1.4

if(typeof jQuery == 'undefined'){
if(typeof document.getElementsByClassName == 'function'){
document.getElementsByClassName('wpsr-floatbar-float_left')[0].style.display = 'none';
console.log('WP Socializer float bar: There is a Javascript error in the page and the floatbar is hidden');

var $floatbar = jQuery(".wpsr-floatbar-float_left");
var $anchor = jQuery('.wpsr_floatbts_anchor');

// Init effects

// Position the left float bar to the anchor
var wpsr_position_floatbar = function(){
anchorOffset = jQuery('.wpsr_floatbts_anchor').offset();
barDistance = jQuery('.wpsr_floatbts_anchor').attr('data-offset');

position: "absolute",
top: + "px",
left: (anchorOffset.left - $floatbar.outerWidth() - barDistance)

// On window scroll
if(jQuery(".wpsr-floatbar-movable").length > 0){
var b = jQuery(window).scrollTop();
var d =;
var c = $floatbar;
c.css({position:"fixed", top: "30px"});
c.css({position:"absolute", top: + "px"});


// **
minLeftShareBar(); // Since v2.4.9

// **
var minLeftShareBar = function(){
if(typeof window.innerWidth !== 'undefined' && window.innerWidth < 800 ){

window.addEventListener("load", wpsr_position_floatbar, false);}
else if (window.attachEvent){
window.attachEvent("onload", wpsr_position_floatbar);


var shareBarWidth = jQuery('.wpsr-floatbar-bottom_fixed').width();
var hideShareBar = function(){
var $this = jQuery('.wpsr_hidebt');
$this.siblings().fadeOut('slow', function(){
width: '20px'
}).attr('data-hidden', 1);

var showShareBar = function(){
var $this = jQuery('.wpsr_hidebt');
width: shareBarWidth
}, function(){
}).attr('data-hidden', 0);


if(jQuery(this).parent().attr('data-hidden') == 1){


Luis Abarca comments:

No, i can see the source code from your site, i think the PHP Notice is breaking some code on your site and avoid to run the rest of the scripts, can you hide all the PHP errors ?, cause the error is from WP Socializer plugin.

Zac Eckstein comments:

I just figured it out. The plugin uses the_content to figure out where to place the floating bar on the left. My custom post types don't use the_content because they are made up entirely of custom fields. I've contacted the plugin author to see if there is a way to change this so it doesn't need to use the_content.

Thanks for trying to help though, I'll give you the $10 for sticking with me few a while!

Luis Abarca comments:

Thanks Zac! and please, let me know if i can help you later in this issue.


Kyle answers:

It doesn't have to do with the js I believe. You have an error on your template wp-content/plugins/wp-socializer/includes/wpsr-socialbuttons.php on line 361 which is blocking the element

Zac Eckstein comments:

But it's working fine on most pages/posts. So I don't think this is the issue.