Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've got a client who is using WordPress and WooCommerce.

I'm trying to add a button to a file. I can get the button to show up, both in the front end editor, and in the template files. But I can't get it to function, nothing happens on hover or on click. No matter which theme I try.

I assume it's the way WordPress handles JavaScript, but I'm not 100% sure. What the button is supposed to do is when clicked on a pop up from myregistry.com appears and the user can then add a product to the registry.

I don't know very much JavaScript yet, I have used a little jQuery but mostly in the form of plugin's, with some minor changes here and there.

So, how could I get this to work inside of Wordpress?

Any help or tips would be great.

    <!-- Start AddToMyRegistry Button Tag --> 
 `<script id='scriptMyRegistryWebWidgetButtonScript' type='text/javascript'>` 
 `document.write("<img id='ImgAddToMyRegistryButton' src='http://images.myregistry.com/Images/MyRegistry/WebWidgetImages/netSol/742.jpeg' onmouseover='ImgAddToMyRegistryButton_onmouseover(this);' onmouseout='ImgAddToMyRegistryButton_onmouseout(this);' style='border-width: 0px; cursor: pointer;' onclick='CreateAddToMyRegistryWidget();' />"); 
 function ImgAddToMyRegistryButton_onmouseover(elementParam) 
 {elementParam.src = 'http://images.myregistry.com/Images/MyRegistry/WebWidgetImages/netSol/742.jpeg';} 
 function ImgAddToMyRegistryButton_onmouseout(elementParam) 
 {elementParam.src = 'http://images.myregistry.com/Images/MyRegistry/WebWidgetImages/netSol/742.jpeg';}` 
 `</script>` 
 `<!-- End AddToMyRegistry Button Tag -->`
share|improve this question
    
In the template which displays your button you can use wp_enqueue_script() to include your javascript. checkout codex.wordpress.org/Function_Reference/wp_enqueue_script . –  rexposadas Feb 17 '12 at 18:54
1  
Close-voted as off-topic. Getting a JavaScript button to work properly is a JavaScript/HTML question, not a WordPress question. –  Chip Bennett Feb 17 '12 at 18:54
    
@ChipBennett Oops, I submitted my comment before I saw yours. Didn't mean to try to reopen the question. –  rexposadas Feb 17 '12 at 18:57
    
idk... adding this script to WP does seem like a WP question. whether the script works or not is another issue. –  helgatheviking Feb 17 '12 at 19:24
    
@helgatheviking as written, the question isn't WordPress specific. There are certainly related questions/issues that would be WordPress specific, but this question doesn't appear to get there. –  Chip Bennett Feb 17 '12 at 21:41
show 1 more comment

closed as off topic by Chip Bennett, toscho Apr 7 '12 at 21:11

Questions on WordPress Development Stack Exchange are expected to relate to WordPress within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

you could filter it onto the end of the_content?

function kia_add_registry_button($content){ ?>
 $content .= "<!-- Start AddToMyRegistry Button Tag --> 
 <script id='scriptMyRegistryWebWidgetButtonScript' type='text/javascript'> 
 document.write("<img id='ImgAddToMyRegistryButton' src='http://images.myregistry.com/Images/MyRegistry/WebWidgetImages/netSol/742.jpeg' onmouseover='ImgAddToMyRegistryButton_onmouseover(this);' onmouseout='ImgAddToMyRegistryButton_onmouseout(this);' style='border-width: 0px; cursor: pointer;' onclick='CreateAddToMyRegistryWidget();' />"); 
 function ImgAddToMyRegistryButton_onmouseover(elementParam) 
 {elementParam.src = 'http://images.myregistry.com/Images/MyRegistry/WebWidgetImages/netSol/742.jpeg';} 
 function ImgAddToMyRegistryButton_onmouseout(elementParam) 
 {elementParam.src = 'http://images.myregistry.com/Images/MyRegistry/WebWidgetImages/netSol/742.jpeg';} 
 </script> 
 <!-- End AddToMyRegistry Button Tag -->";
 return $content;
<?php }
add_filter('the_content','kia_add_registry_button');

having just worked w/ woocommerce i know that it has quite a few hooks you could also use to attach this to.

EDIT: this goes into your functions.php and will add this code to the end of every post/page/product... unless we add further refinement with conditional tags.

share|improve this answer
    
Hey, thanks for the reply. I have an idea of what your saying. Sorry.. still kind of new at this. So, the first line starting with (function), is basically saying, hey.. we need this button and we are calling it content. The second line says. This is what the content is. Then the return content, i put in the template, so it returns what we just did above. and the add_filter, I'm lost. So, do I take the whole code and throw it into where I want, or do I add it all to my functions.php except for the return content. Sorry again, trying to grasp it. –  Christopher Feb 17 '12 at 20:09
    
the whole thing goes in functions.php. explaining filters in a comment just isn't going to happen: codex.wordpress.org/Function_Reference/add_filter don't feel bad if you don't get it, i find them to be one of the least intuitive things and it took me a long time to understand them. –  helgatheviking Feb 17 '12 at 21:06
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.