Jump to content
Sign in to follow this  
JasonLA

Hooks in Base functions.php

Recommended Posts

JasonLA

Just need a little bit of help if you wouldn't mind. I have been trying to add a like button the top of my page right under the facebook, youtube, and twitter buttons. Everytime I add a hook to the code and update it, it gives me a critical error message and I have to go into the server to correct it. I used the code that I found in the forums that others have suggested so I do not know what the problem is. Any suggestions would be appreciated. Thanks!

Share this post


Link to post
Share on other sites
Rob
Jason, please provide a link to your site. Do you have platformbase activated? Are you using the correct hook? There are several variables.

Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
JasonLA
http://zoxstraps.com/ I did have platform base activated and I used this code: ` add_action('pagelines_before_branding_icons','add_AWD_likebutton'); function add_facebook(){ echo 'test'; } `

Share this post


Link to post
Share on other sites
JasonLA
I also just used this code and had the same issues. // add_action('pagelines_after_branding','AWD_likebutton'); add_action('pagelines_after_branding', 'AWD_likebutton'); // function name function likebutton(){ // what the function does???‚¬???in this case adds a stumbleupon icon to the header of your theme. The class referenced in the link can be seen in the style.css // and is the image from the CSS is placed in the images folder ?>

Share this post


Link to post
Share on other sites
Simon
please paste the file to pastie.org or pastebin

Share this post


Link to post
Share on other sites
JasonLA
What file do you want me to paste?

Share this post


Link to post
Share on other sites
Simon
the one giving you the error

Share this post


Link to post
Share on other sites
JasonLA
I did that and pasted it into functions.php and it shut my site down again

Share this post


Link to post
Share on other sites
Simon
what? No copy the whole file that breaks the site to pastebin, and show me it, then i can see where the error is.

Share this post


Link to post
Share on other sites
JasonLA
Oh sorry about that. Here you go! Thanks!

Share this post


Link to post
Share on other sites
Simon
here the section breaking it: [code] // add_action('pagelines_after_branding','AWD_likebutton'); add_action('pagelines_after_branding', 'AWD_likebutton'); // function name function likebutton(){ // what the function does???‚¬???in this case adds a stumbleupon icon to the header of your theme. The cla.... // and is the image from the CSS is placed in the images folder ?> [/code] add_action needs two parameters : 1. the action to hook into. 2. the function to add to the action. so you add_action is saying add AWD_likebutton to pagelines_after_branding. ok so first of all, you have not included a AWD_likebutton function, instead you have function likebutton() Also, php functions HAVE to have an open and a close brace, you have not closed the function! working code: [code] add_action('pagelines_after_branding', 'AWD_likebutton'); // function name function AWD_likebutton() { // php goes here... } // end function [/code] btw you do not need a closing ?>

Share this post


Link to post
Share on other sites
JasonLA
Thank you so much, what kind of php do i put towards the bottom?

Share this post


Link to post
Share on other sites
Jenny
I don't know PHP well but I assume Simon is talking about the PHP code for the AWD_likebutton. It's not going to automagically work, you have to tell it what to do. But I could be wrong. :)

Jenny :: Web designer at Simple Mama (follow me at @simplemamacom)

Check out Share Me, a social sharing add-on for DMS that is super simple to set up.

Share this post


Link to post
Share on other sites
JasonLA
I was actually putting the code in styles.css which is why it wasn't working but when I put it into functions.php it crashed the site again.

Share this post


Link to post
Share on other sites
Rob
Jason, First, carefully read, re-read and re-re-read this page and watch the video as many times as necessary. I did it 5 times before I finally started to add a hook. http://www.pagelines.com/docs/base-child-theme Second, when adding a hook to functions.php, you need to have the right hook, not just code. In other words, the right snippet tells functions where to apply the function you want to have it do. So Pross' working code will work in functions.php if you carefully, properly and judiciously place it. People will tend to rush and make mistakes with these things. Usually, there's also a snippet of CSS needed to make the function look correct. In your case, adding a social icon will require proper spacing or they will overlap or move to all sorts of places. Let's deal with that once you actually get the functions.php done right. Please DO NOT ADD CSS to style.css. We very carefully and wisely provided you with the Custom Code - CSS Rules section so you can dynamically add CSS that can be changed as you need it. The Custom Code will override the style.css every time, so if you add something to Custom Code later, you could overwrite anything added to style.css making that fail. Your site is crashing I think, because you're making fast decisions without doing your due diligence and researching how things are done. Happens to everyone. Take time. Take it easy. Take it slowly and you'll get it.

Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
Jenny
Just to make sure, you're entering the code in functions.php of PlatformBase, correct?

Jenny :: Web designer at Simple Mama (follow me at @simplemamacom)

Check out Share Me, a social sharing add-on for DMS that is super simple to set up.

Share this post


Link to post
Share on other sites
JasonLA
Simple_mama, yes, that is correct.

Share this post


Link to post
Share on other sites
Jenny
I've asked @pross to take a look at this again.

Jenny :: Web designer at Simple Mama (follow me at @simplemamacom)

Check out Share Me, a social sharing add-on for DMS that is super simple to set up.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×