WordPress.org

Forums

Jetpack by WordPress.com
[resolved] sharing buttons on home page but not excerpts (8 posts)

  1. Gretchen Louise
    Member
    Posted 2 years ago #

    I'd like to display the sharing buttons on the home page, but not on excerpts and archives. It seems like it should be a simple line of code to change this, but I can't land on the right combination. Thanks for any help.

    (I would also like the sharing buttons to appear at the top of the post on the home page, but the top and bottom of other single posts/pages.)

    https://wordpress.org/plugins/jetpack/

  2. Richard Archambault
    Happiness Engineer
    Plugin Contributor

    Posted 2 years ago #

    Hi Gretchen!

    Have a look at this:

    http://jetpack.me/2013/06/10/moving-sharing-icons/

    It should give you all you need for specifying on what templates and *where* on those templates yuou want the sharing code to appear, but if you need further help, let me know, that's what I'm here for!

  3. Gretchen Louise
    Member
    Posted 2 years ago #

    Hi Richard,
    I'm actually not using templates, but adding the actions via functions.php

    Here's what I have. It's working everywhere except for the bottom of the post.


    //* Remove default Jetpack share locations
    function jptweak_remove_share() {
    remove_filter( 'the_content', 'sharing_display',19 );
    remove_filter( 'the_excerpt', 'sharing_display',19 );
    }
    add_action( 'loop_start', 'jptweak_remove_share' );

    //* Add Jetpack share buttons above content on home and single pages
    add_action( 'the_content', 'sp_share_buttons_above_post', 19 );

    function sp_share_buttons_above_post( $content = '' ) {
    if ( is_front_page() || is_single() ) {
    return sharing_display() . $content;
    } else {
    return $content;
    }
    }

    //* Add Jetpack below posts single pages
    function sp_share_buttons_below_post() {
    if ( is_single() ) {
    return sharing_display();
    }
    }

    add_action( 'genesis_entry_footer', 'sp_share_buttons_below_post', 19 );

  4. Richard Archambault
    Happiness Engineer
    Plugin Contributor

    Posted 2 years ago #

    Hey Gretchen,

    Could you post your site URL here, so I can have a look?

    If you want it to remain private, you can also contact us via this contact form:
    http://jetpack.me/contact-support/

    Make sure to include a link to this thread in your message.

    I ask, because it seems to me that genesis_entry_footer is for sites that are using (x)html4, so it'd be nice to see what your site is using.

  5. Brandon Kraft
    Happiness Engineer
    Plugin Contributor

    Posted 2 years ago #

    Howdy all,

    For anyone who finds this post seeking the same answer, instead of the last bit of code from the user's example above, try this:

    function sp_share_buttons_below_post( $post_meta ) {
      if ( is_single() ) {
        return sharing_display().$post_meta;
      }
    }
    
    add_filter( 'genesis_post_meta', 'sp_share_buttons_below_post', 10);

    https://gist.github.com/kraftbj/9199140

  6. Gretchen Louise
    Member
    Posted 2 years ago #

    The latest Jetpack update seems to have broken this code's ability to display the share buttons above the post. Has anyone else had this problem?

  7. Richard Archambault
    Happiness Engineer
    Plugin Contributor

    Posted 2 years ago #

    Hi Gretchen,

    Oh no! I don't know what would have changed that would have caused this, however. I'll ask Brandon if he can take a look and confirm this and possibly offer a solution. Thanks for letting me know.

  8. Gretchen Louise
    Member
    Posted 2 years ago #

    Thank you, Richard. Whatever the issue was, it seems to have resolved itself, so perhaps it was only on my site. Thank you for your quick response, though! Sorry to send you and Brandon after an apparent non-issue.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Jetpack by WordPress.com
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.