• Resolved andy0829

    (@andy0829)


    I have someone that used a hashtag like this – #M&S

    The plugin only converts the first section up to the & symbol –

    Like this – #M the rest is ignored after the & and is still plain text.

    Also , I don’t suppose there is a simple way to convert @someone-on-twitter to a working link ? or do i need something else for that ?

    Any way , great plugin and thanks ??

    https://www.ads-software.com/plugins/wp-hashtags/

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Contributor Ismail

    (@elhardoum)

    Hey Andy!

    Thanks for awesome review!

    Sadly #M&S is not a valid hashtag, just go ahead and try it out on Twitter and you will find out. Instead, #M_S is and will work.

    The second one, that is not in the plugin’s features for the current time. It could be achieved with a simple script, let me know if you want that, or try this plugin https://www.ads-software.com/plugins/twitter-link/ but it will filter only post/page content.

    Thank you.
    Samuel

    Thread Starter andy0829

    (@andy0829)

    Thanks Samuel , that sounds right. The & was in a post that was made by the user.

    If there is some code to convert @mentions , that would be great.

    Thanks again

    Plugin Contributor Ismail

    (@elhardoum)

    Hi Andy!

    Try adding this to your child theme’s functions file or with a custom plugin

    /**
      * Parsing usernames and mentions and converting them into Twitter profile
      * links. Targets post/page content, comment text, widget content, bbPress
      * topics and replies, and BuddyPress activities.
      *
      * By @Samuel_Elh
      */
    
    class WP_8008513
    {
    
    	protected static $instance = null;
    
    	public static function instance() {
    
    		return null == self::$instance ? new self : self::$instance;
    
    	}
    
    	function __construct() {
    
    		$this->init();
    
    	}
    
    	function filter( $content ) {
    
    		$pattern	= '/[@]+([A-Za-z0-9-_\.@]+)\b/';
    		$replace	= '<a rel="nofollow" target="_blank" href="https://twitter.com/'.strtolower('\1').'">@\1</a>';
    		return preg_replace($pattern,$replace,$content);
    
    	}
    
    	function init() {
    
    		add_filter('the_content', array( $this, 'filter'));
    		add_filter('widget_text', array( $this, 'filter'));
    		add_filter('widget_title', array( $this, 'filter'));
    		add_filter('comment_text', array( $this, 'filter'));
    
    		if( function_exists('bbpress') ) :;
    			add_filter('bbp_get_topic_content', array( $this, 'filter'));
    			add_filter('bbp_get_reply_content', array( $this, 'filter'));
    		endif;
    
    		if( function_exists('buddypress') ) :;
    			add_filter('bp_get_activity_content_body', array( $this, 'filter'));
    		endif;
    
    	}
    
    }
    
    WP_8008513::instance();

    Let me know.

    Samuel

    Thread Starter andy0829

    (@andy0829)

    Thank you , works great. ??

    Any way to target single posts only with an ‘if is’ –

    add_filter('the_content', array( $this, 'filter'));

    Plugin Contributor Ismail

    (@elhardoum)

    Hey!

    Well, then change this line add_filter('the_content', array( $this, 'filter')); to

    if( is_single( array( 1, 2 ) ) ) :;
    	add_filter('the_content', array( $this, 'filter'));
    endif;

    And change 1, 2 to your desired post IDs, be careful with the commas. [e,g array( 1, 2, 3 ) ; array( 1 )]

    Thread Starter andy0829

    (@andy0829)

    Ok Thanks , That doesn’t work for me. I’d like it to only convert on single posts and not static pages. Even if i add a correct post ID , the code above doesn’t work.

    Thanks anyway ??

    Plugin Contributor Ismail

    (@elhardoum)

    Hi Andy.

    I am sorry to hear it didn’t work. I can understand that you want to exclude pages from the hashtag parsing right?

    Please update to version 0.2.1 which we came to release, and add this code after edit, to your theme functions file (child theme):

    add_filter('wpht_filter_content', function( $content, $original_content ) {
    
    	global $post;
    	$ignored = array( 1, 2, 3, 4 );
    
    	if( in_array( $post->ID, $ignored ) ) {
    		$content = $original_content;
    	}
    
    	return $content;
    
    }, 10, 2);

    You can also use 'page' == $post->post_type instead of in_array( $post->ID, $ignored ) in case you wanted to prevent parsing hashtags for pages.

    Let me know if anything has worked for you. And it is fine let’s get this little issue resolved ??

    Samuel

    Plugin Contributor Ismail

    (@elhardoum)

    Wait, please confirm if you are talking about the hashtags, the main plugin, and not the usernames snippet of code I give earlier.

    Thread Starter andy0829

    (@andy0829)

    The main plugin was fine for me , i only wanted it for the usernames snippet. Trying to get that on all single posts , not pages , sorry for the confusion.

    The new version of the Hashtag plugin throws an error in admin and front-end –

    Fatal error: Call to undefined function bbp_find_mentions_pattern() in C:\Local Develpment\www.test.dev\wp-content\plugins\wp-hashtags\index.php on line 90

    I’ve switched back to the old version.

    Thread Starter andy0829

    (@andy0829)

    For the usernames snippet i ended up using this in my functions –

    function convert_twitter_link($content) {
    	if (is_single()) {
    	global $post;
    	$pattern	= '/[@]+([A-Za-z0-9-_\.@]+)\b/';
    	$replace	= '<a rel="nofollow" target="_blank" href="https://twitter.com/'.strtolower('\1').'">@\1</a>';
    	return preg_replace($pattern,$replace,$content);
    	} else {
    	return $content;
    }
    }
    
    add_filter('the_content','convert_twitter_link',10);

    This works for usernames on post’s only , pages return the content.

    Thread Starter andy0829

    (@andy0829)

    obviously that won’t work for comments , etc only post content

    Thread Starter andy0829

    (@andy0829)

    Bad news Samuel …

    The original version (wp-hashtags.0.1) of the plugin works for me on a Local Dev site , but when i try and install it on live site it fails on the settings page. ? It’s very odd.

    The plugin ‘works’ on live site but you cannot access the settings page in the Admin. On a live site , this error occurs when you try and access the Admim settings page.

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in /var/sites/d/dev.mydomain.co.uk/public_html/wp-includes/plugin.php on line 525

    which is this line it’s referring to on plugin.php –

    call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));

    Also , when activated on a live site, it is converting commas as below –

    with the comma becoming – #8220 displayed as a click-able link to twitter.

    It is finding ” and converting this to a twitter link.

    it’s also converting ‘…’ to a twitter link , this is known as an Ellipsis character.

    with this #8230 displayed as a click-able link to twitter.

    It also adds this to the head of the page before the loop –

    #8230; New Blog!" />

    All instances of ‘ or ” or ? or ; in the post become links

    None of the above happens on a Local Dev site , only when i put it live on the web.

    I tried it on another live just to make sure it’s not something odd with that site , and it was exactly the same.

    A bit lost with this , so I’ve had to deactivate it for now.

    Thanks for trying

    Plugin Contributor Ismail

    (@elhardoum)

    Hi Andy.

    Sorry I had to be away for some time.

    Please update to 0.2.3 and let me know if the plugin has stopped converting quotes, commas, and encoded entities in general into links, and please explain to me the issue you are having with the usernames and I will be glad if I could help you sort it out.

    Thank you, and have a nice day.

    Regards,
    Samuel

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘hashtag with &’ is closed to new replies.