Community Forums › Forums › Archived Forums › Design Tips and Tricks › Wintersong / entry-footer question
Tagged: Addthis, javascript
- This topic has 7 replies, 2 voices, and was last updated 10 years, 2 months ago by Hawkeye.
-
AuthorPosts
-
February 4, 2014 at 5:08 pm #88628HawkeyeParticipant
Hi,
I'd like to add share buttons to the entry-footer, which currently contains the entry-meta information in this theme. My problem is that no matter how I come at the task I end up adding share buttons to pages and other content as well.
I only want the share buttons to display at the bottom of each post, in the same way that the meta info only appears in that location. I can get the share buttons to display correctly using CSS but I can't figure out how to get them to only display after posts.
I have tried every hook available so I'm guessing the issue is a bit deeper than that. Any help appreciated.
Mark
P.S. No link to site because I'm working on this locally.
February 4, 2014 at 8:59 pm #88659nutsandboltsMemberWhat method/snippet are you using to add the share buttons?
Andrea Whitmer, Owner/Developer, Nuts and Bolts Media
I provide development and training services for designers • Find me on Twitter and Google+February 4, 2014 at 9:17 pm #88678HawkeyeParticipantAndrea,
I'm using Addthis code (javascript), which I've used before on several sites. (Wintersong doesn't really have the space for widgets.)
In previous incarnations of StudioPress themes I simply deposited the code where I wanted it (archive.php, page_blog.php, etc.), but I know that's not how Genesis and the child themes work.
Thanks,
Mark
February 4, 2014 at 9:22 pm #88682nutsandboltsMemberYou should be able to get it to display using something like this in functions.php:
function social_after_posts() { if ( is_single() ) { ?> INSERT JAVASCRIPT HERE <?php } } add_action('genesis_after_entry', 'social_after_posts');
Try that out and let me know if it works.
Andrea Whitmer, Owner/Developer, Nuts and Bolts Media
I provide development and training services for designers • Find me on Twitter and Google+February 4, 2014 at 9:34 pm #88685HawkeyeParticipantI tried it out and it works perfectly, which makes you my favorite person in the whole world. 🙂
Thank you.
Mark
February 4, 2014 at 9:35 pm #88686nutsandboltsMemberAwesome! Glad I was able to help. I'm going to mark this topic as resolved but feel free to open a new one if you have any more questions or run into trouble. 🙂
Andrea Whitmer, Owner/Developer, Nuts and Bolts Media
I provide development and training services for designers • Find me on Twitter and Google+February 6, 2014 at 5:12 pm #89034HawkeyeParticipantJust a follow-up here to make things clear for anyone else who has a similar issue....
My initial description of the problem was faulty because the implementation I attempted was shifted on the page by the category and tag information displayed in the theme. I had the code in the right place, but because of a 'float' it displayed somewhere else, confusing me about what was happening. (A common occurrence with CSS.)
What's working now is putting the AddThis javascript code directly into the genesis_entry_footer hook using the Genesis Simple Hooks plugin. Doing so displays the share buttons where I want them on both individual post pages and the home/blog page, although I have to use CSS to get them to appear exactly as desired. (Another common occurrence with CSS -- but thankfully one it was designed for.)
Mark
February 19, 2014 at 2:07 pm #91256HawkeyeParticipantAn overdue postscript to all of the above....
I tried every possible permutation of Genesis hooks and none of them produced the specific results I was looking for. Either the share buttons displayed on pages I didn't want them to display on or they displayed in locations I didn't want or both.
In the end, it turns out that Amanda's code above was the correct implementation, with one small modification. In addition to specifying that the buttons should appear after single posts, I also needed to include a few other locations where I wanted the buttons to show.
Here is the code that I'm now using to accomplish that goal:
function social_after_posts() { if ( is_home() || is_single() || is_archive() || is_search() ) { ?> INSERT JAVASCRIPT HERE <?php } }
The key line is the 'if' statement, which now includes three additional locations where the social buttons should appear. If you want to add more or delete some of those, there's where you'd do it. (For more on CONDITIONAL TAGS that you can use to tell WordPress what to do, go here.)
In addition, because of the way the Wintersong theme functions, I changed this --
add_action('genesis_after_entry', 'social_after_posts');
-- to this --
add_action('genesis_entry_footer', 'social_after_posts');
-- so the buttons would display in the proper spot.
Mark
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.