Title: Usage with do_shortcode()?
Last modified: November 9, 2016

---

# Usage with do_shortcode()?

 *  [Jan Reilink](https://wordpress.org/support/users/janr/)
 * (@janr)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/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 9 years, 7 months ago by [Jan Reilink](https://wordpress.org/support/users/janr/).
      Reason: code prettify
    -  This topic was modified 9 years, 7 months ago by [Jan Reilink](https://wordpress.org/support/users/janr/).
      Reason: code prettify, try 2

Viewing 1 replies (of 1 total)

 *  Thread Starter [Jan Reilink](https://wordpress.org/support/users/janr/)
 * (@janr)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/usage-with-do_shortcode/#post-8501454)
 * Ok, so unfortunately the plugin is not supported by CoSchedule (source: [https://twitter.com/CoSchedule/status/796745213205237761](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.

 * ![](https://ps.w.org/click-to-tweet-by-todaymade/assets/icon-256x256.png?rev=
   1971786)
 * [Click To Tweet](https://wordpress.org/plugins/click-to-tweet-by-todaymade/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/click-to-tweet-by-todaymade/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/click-to-tweet-by-todaymade/)
 * [Active Topics](https://wordpress.org/support/plugin/click-to-tweet-by-todaymade/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/click-to-tweet-by-todaymade/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/click-to-tweet-by-todaymade/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [Jan Reilink](https://wordpress.org/support/users/janr/)
 * Last activity: [9 years, 6 months ago](https://wordpress.org/support/topic/usage-with-do_shortcode/#post-8501454)
 * Status: not resolved