WordPress.org

Ready to get started?Download WordPress

Forums

Sharebar
Titles with Characters or "." in them break in twitter (3 posts)

  1. rhythmdoctor
    Member
    Posted 3 years ago #

    This is more of a feature request than an issue - but unfortunately, because of the way the plugin just uses the post title, if a writer includes any characters like "&" "'" ".com" "%" etc... it breaks the twitter button. Is there a way that you could encode these prior to passing on to the buttons? I hope that makes sense. Thanks.

  2. rhythmdoctor
    Member
    Posted 3 years ago #

    Well, I fixed it. Feel free to change the code in the plugin where it has.

    function sharebar_filter($input){
    	global $post;
    	$code = array('[title]','[url]','[author]','[twitter]');
    	$values = array($post->post_title,get_permalink(),get_the_author(),get_option('sharebar_twitter_username'));
    	return str_replace($code,$values,$input);
    }

    Change it to

    function sharebar_filter($input){
    global $post;
    $code = array('[title]','[url]','[author]','[twitter]');
    <em>$meta = strip_tags($post->post_title);
    $meta = str_replace(array(<strong>ELEMENTS_HERE</strong>),array(<strong>REPLACEMENTS_HERE</strong>), $meta);</em>
    $values = array(<em>$meta</em>,get_permalink(),get_the_author(),get_option('sharebar_twitter_username'));
    return str_replace($code,$values,$input);
    }
  3. rhythmdoctor
    Member
    Posted 3 years ago #

    Sorry, ignore the bolding and in the second code example - should be

    function sharebar_filter($input){
    global $post;
    $code = array('[title]','[url]','[author]','[twitter]');
    $meta = strip_tags($post->post_title);
    $meta = str_replace(array("\"","”","“","&","%","\n","\r","\t"),array("'","'","'","and"," Percent","'","'","'"), $meta);
    $values = array($meta,get_permalink(),get_the_author(),get_option('sharebar_twitter_username'));
    return str_replace($code,$values,$input);
    }

    Obviously - you can change the array to suit your needs.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags