WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Because of the add_action I'm doing on get_content(), where I'm appending social media icons to the end of the post, it appears that calls to get_the_excerpt() are picking up the part of the javascript and appending it to the end of the text returned from get_the_excerpt(). I suppose this is caused by the fact that the "" tags are being stripped out (due to the fact get_the_excerpt() filters them out) as a partial answer.

However, why is this being picked up by get_the_excerpt() in the first place?

It results in the text:

Here is the excerpt.document.write('')...

if((get_option('myTest_facebook_like') || get_option('myTest_plus1') || get_option('myTest_tweet')) && !get_option('myTest_share_title')){
    add_action('the_content', 'myTest_get_social', 10);

function myTest_get_social($myTest_share = '') {
    global $post;

    if((get_option('myTest_plus1') == '' && get_option('myTest_facebook_like') ==  '' && get_option('myTest_tweet') ==  '') || in_category("dont-show-social", $post ) || get_post_meta($post->ID, '_noShare', true)) return $myTest_share;

    $myTest_share .= '<div class="share" style="margin:10px 0">';

    $myTest_permalink   = is_front_page() ? get_bloginfo('siteurl') : get_permalink();

        $myTest_share .='<script type="text/javascript">document.write(\'<div class="g-plusone" href="'.$myTest_permalink.'" data-size="medium" data-count="true"></div>\');</script>';
        global $post;
        if(get_post_meta($post->ID, '_myTest_plus1_href', true)){$myTest_share .= '<script type="text/javascript">function myTest_plus1(){window.location="'.get_post_meta($post->ID, '_myTest_plus1_href', true).'";}</script>';}
share|improve this question
I'm not sure but you have TAGs in the JS strings. That can cause a lot of issues. Encode the JS string with rawurlencode() and call decodeURIComponent() on this string in JS. Like document.write(decodeURIComponent('<?php echo rawurlencode('<tag>intag</tag>'); ?>'));... See if it helps. And please format your code! – EarnestoDev Oct 23 '11 at 17:14

Read this post. In your myTest_get_social() function, you need to check if the excerpt filter is active. If it is, just return the content and do nothing else:

 if(current_filter() === 'get_the_excerpt')
    return $myTest_share;

 // otherwise, do your stuff
share|improve this answer
not working current_filter() return only the_content in both – OzzyCzech Sep 6 '13 at 12:18

You need to detect when will be filter applicated and skip changes if get_the_excerpt filter will be applicated also

 public function my_content($content) {
   global $wp_current_filter;
   // filter only post content not excerpt 
   if (in_array('get_the_excerpt', $wp_current_filter)) return $content; 
   return 'post content : ' . $content;
 add_filter('the_content', 'my_content');

This issue come when $post->post_excerpt (excerpt) is empty. Wordpress try prepare excerpt from $post->content and call the_content filter.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.