Tagged: x
-
AuthorPosts
-
January 12, 2017 at 12:33 pm #1327540
JaWright357ParticipantI’m trying to add share buttons along with some other content after each post on the blog page. I’ve found a lot of stuff similar, such as editing the wp-single.php file, but this only adds the content to the the page for just that post, not the feed at the root Blog page.
I tried to write a function for this in functions.php, similar to one that I used to add a full width header image, but I don’t think I’m using the right hook. The code is:function custom-after-post() { if(is_home(): ?> <div class="custom-share"> SHARE: <a href="#"><img src="/wp-content/uploads/2017/01/Facebook01-small.png" alt="facebook" width="18" /></a> </div> <?php endif; } add_action('x_before_the_content_end','custom-after-post', 30);I am new to both PHP and wordpress’ blogs, so I’m not sure if I’m even on the right track. Any help or input would be appreciated greatly.
Maybe if I can get some input as to which file controls the output for the root Blog page and not just the single page for each blog post?
January 12, 2017 at 3:01 pm #1327721
JadeModeratorHi there,
Please try the x_after_the_excerpt_end action.
Hope this helps.
January 12, 2017 at 3:53 pm #1327807
JaWright357ParticipantThank you for your suggestion, it led me down a slightly different path.
I’m sure it isn’t exactly proper, however this is how I managed to it working:function add_social_sharing(){ if( is_home() ){ echo do_shortcode('SHARE:   <a href="#"><img src="/wp-content/uploads/2017/01/Facebook01-small.png" alt="facebook" width="18"></a>'); } } add_action('x_before_the_content_end', 'add_social_sharing'); add_action('x_after_the_excerpt_end', 'add_social_sharing');If anyone can tell me how to achieve the same results without using the do_shortcode function, I would appreciate it.
I do realize that shortcode can do this, but I don’t quite like the social media buttons that are supplied, so I’d like to us my own.January 12, 2017 at 6:36 pm #1327933
JaWright357ParticipantAnother question; I’m using YARPP to display related posts and it displays above my custom sharing buttons. How can I reverse the order to get them to show up under the social sharing buttons?
January 12, 2017 at 9:37 pm #1328230
Rue NelModeratorHello There,
Thanks for updating in! Since you are not using any shortcode, you can get rid of the do_shoortcode. Please update your code and use this:
function add_social_sharing(){ if( is_home() ){ echo 'SHARE:   <a href="#"><img src="/wp-content/uploads/2017/01/Facebook01-small.png" alt="facebook" width="18"></a>'; } } add_action('x_before_the_content_end', 'add_social_sharing'); add_action('x_after_the_excerpt_end', 'add_social_sharing');You will need to add a priority number to the code above to make sure that it will display before the YARPP items. Please update the code and use this:
function add_social_sharing(){ if( is_home() ){ echo 'SHARE:   <a href="#"><img src="/wp-content/uploads/2017/01/Facebook01-small.png" alt="facebook" width="18"></a>'; } } add_action('the_content', 'add_social_sharing', 5); add_action('the_excerpt', 'add_social_sharing', 5);Hope this helps. Please let us know how it goes.
January 13, 2017 at 12:12 am #1328359
JaWright357ParticipantThank you for responding. By adding the priority number and shortening the hook to just ‘the_content’ and ‘the_excerpt’, it does switch the positions of the two, however it also hides the content of the posts and adds social sharing buttons at the very top of the page, before the nav menu, header logo and top bar.
I’ve tried different priority numbers and it does the same thing.
If i add the priority numbers with the full hooks like this:add_action('x_before_the_content_end', 'add_social_sharing', 5); add_action('x_after_the_excerpt_end', 'add_social_sharing', 5);The post content shows back up, but it doesn’t switch the order of the social sharing buttons and yarpp.
I’ve tried a javascript solution in the custom fields in the customizer, but it only works on the first post and not the others under it. I also tried jquery, but it took every yarpp element on the page and put it under the social share buttons on the first post.
I had a thought of maybe trying the x_before_view hook to put it before the yarpp file that is being included, but I cant figure out which file it is, or even if it would work.
I’ve been trying everything that I can think of and nothing seems to be working out. This site is for a client and I have a deadline to meet. I’m not really sure what to try next.
January 13, 2017 at 1:04 am #1328398
Rue NelModeratorHello There,
Thanks for updating in!
YARPP and any other plugin will be adding any contents using the hook,
the_contentandthe_excerpt. Instead of using add_action, please use add_filter instead. You can make use of this code instead:function add_social_sharing($content){ if( is_home() ){ $content .= '<p>SHARE:   <a href="#"><img src="/wp-content/uploads/2017/01/Facebook01-small.png" alt="facebook" width="18"></a></p>'; } return $content; } add_filter('the_content', 'add_social_sharing', 5); add_filter('the_excerpt', 'add_social_sharing', 5);We would loved to know if this has work for you. Thank you.
January 13, 2017 at 1:34 am #1328423
JaWright357ParticipantRue Nel, that worked!
Thank you so much for the help and patience.
For some reason it added a line break after the share and the social button, but that was simple enough to do away with.
It’s funny how such a little thing can become so frustrating. Luckily there’s a great community here that is willing to help out.January 13, 2017 at 1:36 am #1328426
LelyModeratorYou’re welcome!
Cheers!
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1327540 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
