• Resolved mouzaia

    (@mouzaia)


    Hello Niall, and thanks for the tweet button.
    Unfortunately, I am not able to choose on which kind of post I want to see a tweet button. So, in your TweetButton.php, i have added, after you :

    // do not include Tweet button(s) in an
    autogenerated excerpt
    // get_the_excerpt filter calls wp_trim_excerpt()
    at priority 10 which triggers the_content filter
    on an empty excerpt string
    
    if ( doing_filter( 'get_the_excerpt' ) ) {
    	return $content;
    }
    // ajout sebastien
    if ( is_page() ) { return $content; }
    if ( !is_single() ) { return $content; }
    // fin ajout sebastien

    Maybe you could add in the admin all the
    necessary code to filter the button ?
    Thanks again.

    https://www.ads-software.com/plugins/twitter/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Niall Kennedy

    (@niallkennedy)

    Adding your own filter to customize plugin behavior allows you to modify behavior in your own code without modifying the plugin code. The plugin update process is easier: you are modifying a behavior instead of a piece of code as it existed at a specific point in time.

    The Tweet button is added to posts through the the_content filter when the feature is enabled. Unhook the filter after the init action priority 10.

    Example:

    function unhook_tweet_button() {
      remove_filter(
        'the_content',
        array('\Twitter\WordPress\Content\TweetButton', 'contentFilter')
      );
    }
    
    if ( is_page() || ! is_single ) {
      add_action('wp', 'unhook_tweet_button');
    }
    
    Thread Starter mouzaia

    (@mouzaia)

    Ooohhh ! I understand the principle, but not the realisation ??

    It does not work !

    array(‘\Twitter\WordPress\Content\TweetButton’, ‘contentFilter’)

    means the complete path to TweetButton ?

    array(‘\home\…\plugins\twitter\src\Twitter\WordPress\Content\TweetButton’, ‘contentFilter’)

    but TweetButton only exist as TweetButton.php so why not :

    array(‘\home\…\plugins\twitter\src\Twitter\WordPress\Content\TweetButton.php’, ‘contentFilter’)

    Of course i see the function contentFilter, but in it, I just see a filter ‘get_the_excerpt’ !

    Then after :
    add_action(‘wp’ ….)

    Why action wp ? should not it be get_the_excerpt ?

    Anyway I have tried all, it does not work.

    Thanks for your time anyway !

    Plugin Author Niall Kennedy

    (@niallkennedy)

    WordPress and its themes build content in multiple stages, which are exposed in actions. If you would like to change the functionality of your WordPress site you need to add code to change behavior after the behavior is registered but before it is output to the page.

    The Twitter plugin for WordPress adds a Tweet button before and/or after post content by acting on a WordPress filter: the_content. Post content such as “hello world” is passed through the_content filter before being output to the page, allowing a plugin to act on its content. At the most basic level a plugin could add the text ” Tweet button” to the end of every post, returning a new string of “hello world Tweet button.”

    You would like to change the behavior of a plugin. Luckily it uses WordPress actions to hook into WordPress. It can be unhooked as well.

    A Tweet button is possibly added to post content during the init WordPress action by registering as a callback function using add_filter.
    https://plugins.trac.www.ads-software.com/browser/twitter/tags/1.1.0/src/Twitter/WordPress/PluginLoader.php#L196

    You can remove the plugin’s callback from the_content if your conditionals are met using the remove_filter function.
    https://codex.www.ads-software.com/Function_Reference/remove_filter

    Thread Starter mouzaia

    (@mouzaia)

    I am sorry Niall, to come back, but it does not work at all.

    function unhook_tweet_button() {
      remove_filter(
        'the_content',
        array('\Twitter\WordPress\Content\TweetButton', 'contentFilter')
      );
    }
    add_action('wp', 'unhook_tweet_button');

    The action should be added always, so I should never see the button Tweet, and I always see it !
    So ?
    \Twitter\WordPress\Content\TweetButton
    i understand now, the namespace Twitter\WordPress\Content; and the class TweetButton !
    Then
    add_action('wp', 'unhook_tweet_button');
    then the button should desappear. But no !

    I understand your time is precious and I apologyze, but maybe someone else can help, but please, dont “resolved” that discussion.

    Regards.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Tweet button not in pages, or in a post when opened’ is closed to new replies.