Jump to content
Sign in to follow this  
evanders

Hooks no longer functioning in 2.0

Recommended Posts

evanders

I upgraded to Framework 2.0 and now my hooks using the "pagelines_after_[name]" action aren't functioning any more. Specifically, I have a hook that references the action "pagelines_after_excerpt" to insert some custom social share buttons under each excerpt. I know the code is good because when I change the action to something different like "pagelines_loop_before_post_content", it works fine. I need some help as I can't find another way to insert content after the excerpt without this. Thanks.

Share this post


Link to post
Share on other sites
kastelic
You can view all the actions and filters in Framework here: http://api.pagelines.com/hooks I think they are trying to move away from so many hooks and using filters instead. So for example you could use pagelines_excerpt and use a filter to add content to it.

Share this post


Link to post
Share on other sites
evanders
Got it. Thank you. Only problem is now, I don't have a clue how to use filters. It seems relatively straightforward. My biggest problem is I don't want to replace the section I'm modifying, I want to add too it. I've pasted my code below. Can you help me out? [code] add_filter('pagelines_excerpt','share_buttons_excerpt'); function share_buttons_excerpt(){ ?>

Share this post


Link to post
Share on other sites
Simon
Ok you are confusing an action with a filter, common mistake. An action is something that is included or added to.. A filter takes something, a variable usually and allows you to manipulate it. Filters ALWAYS have to have the output returned back. Simple rule: Action means you can print stuff to the screen. Filter you can change things before they reach the screen. So lets look at your filter again. [code]add_filter('pagelines_excerpt','share_buttons_excerpt'); // our function takes the excerpt as an input. function share_buttons_excerpt( $excerpt ){ // so this is where you add to the excerpt variable before handing it back. // now we send it back for the framework to print to screen. return $excerpt; } //end function[/code] Now I have no idea which of the 15,000 plugins available you have installed, so I'm going to assume that sharebar_button('email','small'); will simply echo the html, you need it to be passed as a variable like: $share = sharebar_button('email','small'); then you can add it to the excerpt like $excerpt = $excerpt . $share1; Check the plugin docs there may be a new variable to use it so it does not echo.

Share this post


Link to post
Share on other sites
evanders
Thanks a lot. This worked great. The only problem I run into, is for some reason when I use the $share variable, it shows up above the excerpt instead of below. Any ideas?

Share this post


Link to post
Share on other sites
evanders
This is what I referred to in my last post. For some reason, my code (see below) outputs my share buttons first ($share_fb, $share_twitter, $share_gplus, $share_linkedin and $share_email), then the post excerpt, then the div with the class "share-buttons-excerpt" containing [b]nothing[/b]. I can't figure out why it's not placing the share button code within the div I created and outputting it [i][b]below[/b][/i] the post excerpt. Can somebody help me? Here is the code: [code]/* Adds share buttons underneath post excerpts. */ add_filter('pagelines_excerpt','share_buttons_excerpt'); function share_buttons_excerpt( $excerpt ){ $share_fb = sharebar_button('facebook','small'); $share_twitter = sharebar_button('twitter','small'); $share_gplus = sharebar_button('google+','small'); $share_linkedin = sharebar_button('linkedin','small'); $share_email = sharebar_button('email','small'); $share = ''; $excerpt = $excerpt . $share; return $excerpt; } //end function[/code]

Share this post


Link to post
Share on other sites
Simon
As is said before, those share functions are not passing the output to the variables, they are simply echoing to the screen. The plugin will have to be adapted.

Share this post


Link to post
Share on other sites
evanders
Honestly, I didn't get it when you first said it. It makes a lot more sense for whatever reason now. Thanks again.

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  

×