• Hi,

    I’m trying to add the @anywhere tweetbox to my theme after the content. Here’s the code I’m using:

    function insertSharingBlock($content) {
    	        if(!is_feed() && !is_home()) {
    	                $content.= "<div class='share-area'>";
    	                $content.= "<div class='tweet-anywhere-box'>";
    	                $content.= "<div id=\"tbox\"></div>";
                      $content.= "<script type=\"text/javascript\">";
                      $content.= "  twttr.anywhere(function (T) {";
                      $content.= "    T(\"#tbox\").tweetBox({";
                      $content.= "      height: 26,";
                      $content.= "      width: 400,";
                      $content.= "      label:\"<link rel='stylesheet' href='path/to/my/style.css' type='text/css' media='screen'>Tweet this post!\",";
                      $content.= "      defaultContent: \"Hello\"";
                      $content.= "    });";
                      $content.= "  });";
                      $content.= "</script>";
    	                $content.= "</div>";
    	                $content.= "</div>";
    	                $content.="<div class='clear'></div>";
    	        }
    	        return $content;
    }
    add_filter ('the_content', 'insertSharingBlock',1);

    crucial is this line:
    $content.= " label:\"<link rel='stylesheet' href='path/to/my/style.css' type='text/css' media='screen'>Tweet this post!\",";

    This is a hack to insert a stylesheet for the tweetbox (currently the only way of styling it, admitted by the twitter dev team). The string of the label is inserted in a label element. By inserting a link element, one can inject one’s own stylesheet. Coded like this, this results in the following code generated (showing only script tag and not divs):

    <script type="text/javascript">  twttr.anywhere(function (T) {    T("#tbox").tweetBox({      height: 26,      width: 400,      label:"
    <link rel='stylesheet' href='http://dotnomad.com/wp-content/themes/magazinum.nomad/style.css' type='text/css' media='screen'>Tweet this post!",      defaultContent: "Hello"    });  });</script>

    A newline is inserted after the opening double quote of the label string, resulting in an unterminated string literal. Replacing the opening and closing brackets with the entities < > does not result in the newline being added and thus does not produce the error. OF course, this also does not insert a link element, which was the objective.

    I’m fairly new to WP development, so I’m clueless as to what is going on. Would it be the KSES that is interfering? Is there another way I can code this? Can it be solved.

    Thanks in advance for any input you can give me

    S.

  • The topic ‘filter and returned html’ is closed to new replies.