WordPress.org

Support

Support » Plugins and Hacks » Twitter Tools » [Plugin: Twitter Tools] Feature request: use variables in tweet prefix

[Plugin: Twitter Tools] Feature request: use variables in tweet prefix

Viewing 1 replies (of 1 total)
  • In the meanwhile I wrote a short hook which should do the case I think.. you have to set the tweet prefix to {category} and put the code somewhere in your theme (functions.php for instance).

    function twitter_category_prefix($tweet = FALSE, $post = FALSE) {
    	$replace_str = '{category}';
    
    	if($tweet && $post && isset($post->ID) && strpos($tweet->tw_text, $replace_str) !== FALSE) {
    		// Find categories for this post
    		$categories = get_the_category($post->ID);
    		if(count($categories) > 0) {
    			// Replace first category name in tweet text
    			$tweet->tw_text = str_replace($replace_str, $categories[0]->name, $tweet->tw_text);
    			return $tweet;
    		}
    	}
    	else {
    		return $tweet;
    	}
    }
    add_filter('aktt_do_blog_post_tweet', 'twitter_category_prefix', $priority = 10, $amount_of_args = 2);
Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Twitter Tools] Feature request: use variables in tweet prefix’ is closed to new replies.
Skip to toolbar