• Resolved Hunterwolf

    (@hunterwolf88)


    Hello!
    Sorry for the weird request, but I’d like to force all the user submitted comments and posts (users are able to post on this website thanks to “User Submitted Posts” plugin) to be uppercase.
    I used CSS text transforme till now, to show all the posts and comments uppercase, but I’d like the text is *really* uppercase, not just a visual workaround.
    Anyone already tried a script for that? ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi,

    You can use strtoupper php function and hook to get_comment_excerpt probably to filter comment text there. Something like this should work I think:

    
    add_filter( 'get_comment_excerpt', 'capitalize_comments' );
    function capitalize_comments( $excerpt ) {
      return strtoupper( $excerpt );
    }
    

    I’m not sure what hook you can use in “User Submitted Posts” plugin – you’ll need to check code they have in templates.

    Thanks

    Hallo @hunterwolf88,

    I strongly recommend NOT do convert comments and user posts to uppercase. It has a direct impact on the readability and therefore an impact of SEO in second place.

    I’m also keen why you didn’t want to format the text via CSS. In case you don’t like the uppercase comments after a while you can simply adjust your CSS code. Converting all comments to real uppercase means there’s no way back on a later point in time.

    Anyway, you’re here for a solution, not a preach, right? Feel free to knock yourself out by adding the following code snippet to your functions.php:

    add_action('wp_insert_comment', 'comment_to_uppercase', 99, 2);
    function comment_to_uppercase($id, $object) {
        $data = (array) $object;
        $data['comment_content'] = strtoupper($object->comment_content);
        wp_update_comment($data);
    }

    Please note that this snippet on only affects the comments, not the user posts.

    Have fund with the snippet and have a great weekend!

    Niels

    • This reply was modified 7 years, 6 months ago by Niels Lange.
    • This reply was modified 7 years, 6 months ago by Niels Lange.
    Thread Starter Hunterwolf

    (@hunterwolf88)

    thank you for your help guys!
    @nielslange I am aware of the limitations of that, and the consequences on readability (but that’s exactly what I need).
    However I did not consider the possible consequences on SEO.
    Maybe I’ll use a special font that appears in “caps lock” also when it actually isn’t ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘force comments and post to be uppercase’ is closed to new replies.