Viewing 1 replies (of 1 total)
  • Thread Starter stefandoorn

    (@stefandoorn)

    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.