WordPress.org

Ready to get started?Download WordPress

Forums

ShareThis: Share Buttons and Social Analytics
Remove share-this from the_excerpt()? (35 posts)

  1. Anointed
    Member
    Posted 1 year ago #

    How do I remove the share-this links from my blog index page?

    My blog index page is set to show the_excerpt(), instead of the_content().

    The problem is I end up with a page showing hundreds of sharethis links all over the place and it looks really stupid.

    I'd like to set it up so that the links are only on single post or single pages, not the archives. Can't seem to find directions on this, and there seems to be no setting in the admin for this.

    http://wordpress.org/extend/plugins/share-this/

  2. Anointed
    Member
    Posted 1 year ago #

    Here is a great example of how bad it looks having share-this in the excerpt http://bit.ly/U8JLuQ

  3. sharethissupport
    Member
    Posted 1 year ago #

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

    Hi Sir,
    If you want to add the sharethis buttons to post-pages only, you will have to add the sharethis code manually to your templates since this isn't possible with the sharethis plugin.

    You can get the code (by selecting website platform is step 1 from here:http://sharethis.com/publishers/get-sharing-tools)
    Please note that you will have to modify the span tags as explained below.

    Sharethis script and span tags go on the page where you want the buttons to appear and they also determine what kind of button appears as well as what URL and title it shares. You will have to put these in your Single Post template (single.php) in order to add the buttons only to the post-pages.

    Depending upon the position of buttons on a page, you will have to decide the position of the code in th file single.php
    You can add:
    Sharethis script tags below the line:

    get_header(); ?>

    AND

    span tags below the line of code:

    <?php get_template_part( 'content', 'single' ); ?>

    Here is the basic span for just the ShareThis button:

    <span class="st_sharethis" st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText="ShareThis"></span>

    You can change the class of the span to determine the button that appears. For example class="st_twitter" will make a twitter icon and class="st_email_vcount" will make a email vertical counter button.

    You can read more about the different types of buttons here: http://help.sharethis.com/customization/customization-overview

    [ sharethissupport, all of your posts are being held in moderation and will need to be approved before users can see them. Please follow the rules and refrain using signatures in your reply posts. ]

  4. Anointed
    Member
    Posted 1 year ago #

    Ok, I couldn't believe for a second that there wasn't a way of doing it within the plugin so you made me go dig into the code and I found:

    if (get_option('st_add_to_content') != 'no' || get_option('st_add_to_page') != 'no') {
    	add_filter('the_content', 'st_add_widget');
    
    	// 2008-08-15 Excerpts don't play nice due to strip_tags().
    	add_filter('get_the_excerpt', 'st_remove_st_add_link',9);
    	add_filter('the_excerpt', 'st_add_widget');
    }

    Would you please add a filter to the next vs. of sharethis so that we can simply use a filter to do this?

    Right now, all I have to do is comment out the last 2 add_filter...
    and it solves the problem.

    Now I'd rather not have to modify your plugin every time there is a new release, so if you would please follow WordPress coding standards and add in a filter hook there, then we can solve the problem with one line in our themes function file. It would be so easy to allow filters on both the_excerpt() and the_content() so that users could specify what they wanted.

    Heck even better:::::
    Why not hook it into the pre_get_posts() function on a per post-type basis, so we could then have ultimate control via filters?

    thanks.

  5. sharethissupport
    Member
    Posted 1 year ago #

    HI,
    Thanks for such a nice suggestion.
    I'll forward it to our team.

    [ sharethissupport, all of your posts are being held in moderation and will need to be approved before users can see them. Please follow the rules and refrain using signatures in your reply posts. ]

  6. Anointed
    Member
    Posted 1 year ago #

    I changed this back to not-resolved as the problem is still there in the latest vs.

    How about this idea for now:
    At the very least, apply a custom class to the <p> wrapper which surrounds the sharing icons. That way, for now, I can at least target the share buttons that I don't want to display to hide them via css.

    While that's a horribly tacky way, it is a quick 2 minute fix for you guys until you decide to do it right.

    You said you forwarded the suggestion....
    Did they give you an e.t.a. on the fix?

    Every single site I have built using this plugin has this problem, and it's rather annoying. The rest of the plugin is awesome, so lets just get this last issue solved and move on.

  7. sharethissupport
    Member
    Posted 1 year ago #

    Hello sir,
    We have noted the point and may add this option to the sharethis plugin in future.
    Right now we don't have plans to add it to the immediate release.
    Also,I don't know ETA on this.
    I will let you know once the product team confirms about it to me.
    Regards,
    The Sharethis Support

  8. Jon Brown
    Member
    Posted 1 year ago #

    LOL... I did the exact same as Anointed... hunt around in their crummy code only to find no hook to fix their lack of basic options. Then coming here and finding this thread.

    Adding an option to display/not display on excerpts requires about 5 lines of code... it took longer to write this email than it'd take to fix it.

  9. cmccrone
    Member
    Posted 1 year ago #

    @Anointed and @Jon Brown

    Put this in your themes Function.php file

    remove_filter( 'get_the_excerpt', 'st_remove_st_add_link', 9 );
    remove_filter( 'the_excerpt', 'st_add_widget' );

    The plugin should have checkboxes to remove from:
    -Home
    -Pages
    -Archive/excerpts
    -Posts

    Pretty dumb.

  10. cmccrone
    Member
    Posted 1 year ago #

    I made this to remove it from single pages.

    if (!is_page_template('page.php')) {
    remove_filter( 'the_content', 'st_remove_st_add_link', 9 );
    remove_filter( 'the_content', 'st_add_widget' );
    }

    Hope this helps you guys out!

  11. YoVenice
    Member
    Posted 1 year ago #

    I tried share-this with Simplepress Forum ... it added share-this to ever user comment .. any idea how to get rid of that, seems like the same issue discussed here - trying to limit where it posts. Thanks!

  12. abetterlife
    Member
    Posted 1 year ago #

    cmccrone
    I am a bit of a novice - what happens when I insert
    your proposed code into function.php?
    remove_filter( 'get_the_excerpt', 'st_remove_st_add_link', 9 );
    remove_filter( 'the_excerpt', 'st_add_widget' );

    Does it give me options somewhere? Can't see any change...
    Thnkx

  13. cmccrone
    Member
    Posted 1 year ago #

    Abettedlife

    That code removes it from showing up in your list of blog articles. The three line code I provided removes it from single pages (not posts/articles). Your homepage, contact page, about us page etc. but no, the code does not add options. It just removes it.

    UPDATE SHARETHIS: As of now there is an option under the share this settings.

    In your admin dashboard, Sidebar > SETTINGS > SHARETHIS and about half way down the page you will see two options.

    Automatically add share this to your posts/pages.

    I leave yes to posts on so people can share your blog items.

    And then say no to pages because its pretty ugly in my opinion.

    Any questions, feel free to ask.

  14. abetterlife
    Member
    Posted 1 year ago #

    thanks cmccrone - that's clear. What I really want to do is remove the buttons from the excerpts, wherever they appear.

  15. cmccrone
    Member
    Posted 1 year ago #

    Ok, I just showed my gf how to do this. She is learning all about blogs at the moment. She has a Love Poems For Her Blog..

    Here is the code she used there to remove the buttons from the excerpts.

    remove_filter( 'get_the_excerpt', 'st_remove_st_add_link', 9 );
    remove_filter( 'the_excerpt', 'st_add_widget' );

    Add that code to your function.php file
    LOCATION: http://lovepoemsforher.com/wp-content/themes/theme-name/function.php

    You can edit it using an FTP tool or logging into wordpress. In the sidebar go to Appearance > Editor > Theme Functions (functions.php) and add the code

    :)

  16. abetterlife
    Member
    Posted 1 year ago #

    thx cmccrone
    yes, just added code. Settings on plugin to show on pages and blogs. But Still showing on excerpts. http://hertscollegeofhypnosisandnlp.co.uk/
    I am using a custom theme from woothemes... And this is the theme that I edited. Any ideas?

  17. abetterlife
    Member
    Posted 1 year ago #

    oops was not editing Theme Functions... now working ok thanks! Great stuff.

  18. abetterlife
    Member
    Posted 1 year ago #

    No - problem again. I get this error message (my wootheme is called matamorphosis) -

    remove_filter( 'get_the_excerpt', 'st_remove_st_add_link', 9 ); remove_filter( 'the_excerpt', 'st_add_widget' );remove_filter( 'get_the_excerpt', 'st_remove_st_add_link', 9 ); remove_filter( 'the_excerpt', 'st_add_widget' );
    Warning: Cannot modify header information - headers already sent by (output started at /home/abl/public_html/hertscollegeofhypnosisandnlp.co.uk/wp-content/themes/metamorphosis/includes/theme-functions.php:46) in /home/abl/public_html/hertscollegeofhypnosisandnlp.co.uk/wp-includes/pluggable.php on line 881

  19. abetterlife
    Member
    Posted 1 year ago #

    despite the error, its now working thx!

  20. abetterlife
    Member
    Posted 1 year ago #

    cmccrone
    nightmare I can't login at wp-admin now! I think it arose from a silly mistake in editing the wrong file - the stylesheet - instead of the functions.php. Please - cany help on how to fix this? I get teh following error message on attempting to got to http://hertscollegeofhypnosisandnlp.co.uk/wp-admin >>>>>>

    remove_filter( 'get_the_excerpt', 'st_remove_st_add_link', 9 ); remove_filter( 'the_excerpt', 'st_add_widget' );
    Warning: Cannot modify header information - headers already sent by (output started at /home/abl/public_html/hertscollegeofhypnosisandnlp.co.uk/wp-content/themes/metamorphosis/includes/theme-functions.php:46) in /home/abl/public_html/hertscollegeofhypnosisandnlp.co.uk/wp-includes/pluggable.php on line 881

  21. cmccrone
    Member
    Posted 1 year ago #

    Just get a free FTP program like FileZilla. You can login to your WordPress files and edit it with a simple text editor just like you do when you're logged in to WordPress.

    Make sense?

  22. abetterlife
    Member
    Posted 1 year ago #

    hi cmccrone
    yes - any ideas which file may be at fault and what might i be looking for?

  23. abetterlife
    Member
    Posted 1 year ago #

    ps the following text now appears at the top of my site (hertscollegeofhypnosisandnlp.co.uk)when viewed:
    remove_filter( 'get_the_excerpt', 'st_remove_st_add_link', 9 ); remove_filter( 'the_excerpt', 'st_add_widget' );

  24. cmccrone
    Member
    Posted 1 year ago #

  25. abetterlife
    Member
    Posted 1 year ago #

    cmccrone
    Excellent help. Thanks. All sorted after my silly error.

  26. pstoaks
    Member
    Posted 1 year ago #

    I don't know if this is a help to anyone else, but I wanted to just completely remove ShareThis from a special page template. I have ShareThis buttons turned off for pages and a shortcode to add them when I want them, but I do use the hover buttons and wanted to eliminate those from pages as well. Putting this at the top of your template.php file should completely remove the functionality from pages that use that template.

    /* Remove the ShareThis stuff en-masse */
    remove_action('wp_head', 'st_widget_head');
  27. syrinx32123
    Member
    Posted 1 year ago #

    thank you @cmccrone your code worked perfectly when added to my Functions.php file!

  28. syrinx32123
    Member
    Posted 1 year ago #

    @cmccrone

    For some reason, my excerpts are still showing up on my category and blog pages under the excerpts. Any idea how to remove them? I added your lines of code to my functions.php

    http://www.travelgrom.com/category/coachella/

  29. WraithKenny
    Member
    Posted 1 year ago #

    I prefer to put this in the theme functions file.

    function remove_sharethis() {
    	if ( ! is_singular( array( 'post', 'page' ) ) ) {
    		remove_filter('the_content', 'st_add_widget');
    		remove_filter('the_excerpt', 'st_add_widget');
    		remove_action('wp_head', 'st_widget_head');
    	}
    }
    add_action( 'template_redirect', 'remove_sharethis' );

    It gets rid of this annoying code except on single posts or pages. Feel free to tailor it how you like, the normal WordPress conditionals will work there.

  30. colleengreene
    Member
    Posted 11 months ago #

    @cmccrone Your functions.php solution for removing it from excerpts worked great. Thank you!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.