Twitter Tools
Feature request: use variables in tweet prefix (2 posts)

  1. stefandoorn
    Posted 3 years ago #

    It would be nice to be able to easily set the Tweet Prefix for instance to the main category used for the post: %c or something could be entered then. Unfortunately now I have to hack the core code for it which makes it not upgrade-supported anymore. Would be a nice feature :-)


  2. stefandoorn
    Posted 3 years ago #

    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);

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Twitter Tools
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.