Support » Plugin: Click To Tweet » Usage with do_shortcode()?

  • I’m trying to use the [tweet] shortcode in a template file, using do_shortcode()‘. Is that possible? (obviously I can’t get it to work…)

    What I’m trying to do is:

        function saotn_related_posts_after_post( $content ) {
            $blog_id = get_current_blog_id();
            if ( $blog_id == "1" && is_singular( 'post' ) ) {
                // [..]
                $content .= do_shortcode('[Tweet ""]');
                // [...]
            }
            return $content;
        }

    Note: the empty Tweet shortcode comes from my code change and feature request. See my email from Fri, 22 Jul 2016 for the following information – for anyone who wants this as well:

    In click-to-tweet-by-todaymade\tm-click-to-tweet.php, add the following
    in the function tweet($matches), below the if (!empty($handle)) {
    block, around line 229:

    $text = ($matches[1] == "") ? get_the_title() : $matches[1];

    This makes the function:

         /**
         * Replacement of Tweet tags with the correct HTML
         */
        public function tweet($matches) {
            $handle = get_option('twitter-handle');
            if (!empty($handle)) {
                $handle_code = "&via=".$handle."&related=".$handle;
            }
    
            $text = ($matches[1] == "") ? get_the_title() : $matches[1];
            $short = $this->shorten($text, 100);
            return "<div class='tm-tweet-clear'> [!snip rest of code!] </div>";
        }
    • This topic was modified 1 year, 11 months ago by  Jan Reilink. Reason: code prettify
    • This topic was modified 1 year, 11 months ago by  Jan Reilink. Reason: code prettify, try 2
Viewing 1 replies (of 1 total)
  • Ok, so unfortunately the plugin is not supported by CoSchedule (source: https://twitter.com/CoSchedule/status/796745213205237761).

    I wasn’t able to include the empty [tweet ""] shortcode into my sites. This may be due to the fact I’m using it in a site specific plugin, instead of functions.php.

    Anyway, I went with adding the entire HTML-code. For future reference (it’s ugly, but it works because the plugin scripts and styles are loaded anyway):

    function saotn_click_to_tweet_after_post( $content ) {
    	// we'er on Multisite
    	$blog_id = get_current_blog_id();
    	if ( is_single() ) {
    		$title = get_the_title();
    		$short = mb_strimwidth($title, 0, 100);
    			$content .= "<div class='tm-tweet-clear'></div>
    						   <div class='tm-click-to-tweet'>
    							<div class='tm-ctt-text'><a href='https://twitter.com/share?text=".urlencode($short)."&url=".get_permalink()."' target='_blank'>".$short."</a>
    							</div>
    						   <a href='https://twitter.com/share?text=".urlencode($short)."&url=".get_permalink()."' target='_blank' class='tm-ctt-btn'>Click To Tweet</a>
    						</div>";
    	return $content;
    }
    add_filter( "the_content", "saotn_click_to_tweet_after_post", 9 );
Viewing 1 replies (of 1 total)
  • The topic ‘Usage with do_shortcode()?’ is closed to new replies.