0

For example somebody replies-

Hi! This is a Comment!

but is published as

Text- Hi! This is a Comment!

Any ideas folks? I'm totally stumped. I want to add the extra text so it appears within the comment rather than before/around it in the theme.

2 Answers 2

2

You can try the comment_text filter:

/**
 * Prepend text to each comment content.
 */

add_filter( 'comment_text', function( $comment_text )
{
    $text = 'Some text';
    return $text . $comment_text;
});

if you're displaying the comment text with:

<?php comment_text(); ?>
5
  • That adds text above the comment, is there a simple fix to having it show on the same line as the comment? If there is or if there isnt, thank you loads for replying to a total newb.
    – Spacecat22
    Jan 14, 2015 at 20:34
  • Welcome to WordPress Development. I'm not sure I follow you there, what you mean by the same line. You can also try out the get_comment_text filter, that's activated before the comment_text filter.
    – birgire
    Jan 14, 2015 at 20:42
  • The comments are displaying Some Text and the Comment with what look like paragraph breaks between them.
    – Spacecat22
    Jan 14, 2015 at 20:45
  • Maybe you could add the current HTML structure of a comment, before and after the filter. So we can better understand how it's working.
    – birgire
    Jan 14, 2015 at 20:48
  • I can't at the moment as I'm being murdered in work but shall post the code later on. Thanks for looking in, its appreciated.
    – Spacecat22
    Jan 14, 2015 at 20:51
0
<script type="text/javascript">
    function addText() { 
        var input = document.getElementById('comment');
        input.value = 'lots of new text ' + input.value;
    }
</script>

<p class="comment-form-comment">
<label for="comment">Comment</label>
<textarea id="comment" name="comment" cols="45" rows="8" aria-describedby="form-allowed-tags" aria-required="true">
</textarea>
</p>        

Ripped bits and pieces from elsewhere online.. eventually. Thanks for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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