Here is function that return you the comment author initials by the comment id
function get_comment_author_initials($comment_id) {
$author = get_comment_author($comment_id);
$words = explode(" ", $author);
$initials = null;
foreach ($words as $w) {
$split = mb_str_split($w); // to cover unicode char
$initials .= $split[0];
}
return $initials;
}
function mb_str_split( $string ) {
return preg_split('/(?<!^)(?!$)/u', $string );
}
And you can use it in your code like this
<div class="class2">
<?php echo get_comment_author_initials($comment->comment_ID); ?>
</div>
Related Posts:
- Change comments form title on a page by page basis
- How do I create comment-reply-button using element not
- Replace comment avatars and links at the same time
- Adding ads code between comments
- How do I fetch all comments per post via WP REST API?
- comments_number display outside specified span
- “comments.php” not available after edit in WP administration
- Ajax load more button for comments wordpress
- Limit 1 global comment per minute
- Create Page To Count Comments For Each Post In WordPress Site
- wp-comments-post.php file returns a blank page
- php function to display commenter username or login
- Alter required message using comment form api
- WordPress comment submit button substitutes/options
- Does anyone know all parameters of get_comments()
- Send a mail to specific address in a custom field when a new comment is made on a specific post
- get_comments_number() returns 0
- comment_post (if comment is approved OR $comment_approved === 1) not working?
- Show all people who commented on all posts by an author
- Display the list of user’s comments + the post title + date
- How do I make comment-reply-button with that takes to comment reply form on click
- How to get the rating value of each comment
- Trouble figuring out how to get my button to submit comment
- How to manually fix the WordPress gallery code using PHP in functions.php?
- How to make a image-size selected by default in Media upload – WP v3.5
- Hide main div if wp_nav_menu is empty
- adding a filter to a shortcode?
- How to draw media details for Isotope gallery using Photoswipe
- Change the footer text on the login page
- Rewriting search and pagination base
- Copyright info change in Theme Child PHP
- show limited tags in an article
- Using a function written in my functions.php file within the header.php file
- Is the regular ajax request method safe or I should use admin-ajax.php?
- Create an array from an array
- Using wp_get_image_editor in a standalone script
- Woocommerce: Is it possible to overide the settings for allowing to purchase out of stock products [closed]
- Can I change a variable in a content part while calling it?
- page template for attachement page?
- PHP Deprecated: WP_RSSjb has a deprecated constructor
- Shortcode return function with link href inside PHP
- Set WordPress Default Template
- Can’t get page content in WordPress
- Function not working at one place
- Showing content from one page on another
- How to insert a single row to WP database table?
- Get date numerical and separate?
- How to check if a meta value has already been assigned to any user?
- How to prevent WP_Query function from returning all posts when empty?
- How to call plugin function per site in a multisite?
- foreach loop still echoes array
- dynamic dependent select dropdown
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- Noscript not working as it should in wordpress site
- Pagination broken on is_front_page()
- Removing the comment function within wordpress
- Content filter won’t work
- Why does the post_type_link hook everything twice?
- use loop to return blog details
- This function is deprecated; use mysql_real_escape_string() instead
- get_theme_mod outputs number when using WP_Customize_Cropped_Image_Control
- Adding an interior ‘hero’ area with some added php title customization
- Custom Taxonomy Select Menu: Setting default option value?
- How to add author’s posts link (HTML + PHP) inside a function to output it
- Enqueueing a code block from an options framework
- Conditional On custom field plugin metabox
- Adding a ‘style=’ bit to image_send_to_editor output
- Post Views Code Hacks
- Closing WP_LINK_PAGES DIV ID w/After Argmuent
- Exclude function from running on a certain page
- Auto create Nextgen Gallery on post creation [closed]
- Hide media for non logged in users
- How to set value selected using select2 jquery plugin
- Workaround for og:image unsupported webp image type, Yoast SEO?
- Jetengine Forms – Media upload path
- Using ACF Relationship field to set post type to draft or published status
- is_front_page is not working in my functions.php
- Is it possible to update the dataset using update_post_meta
- Hide payment method based on user role AND minimum cart value
- How can i avoid duplicate same post in wp?
- Update $wpdb query with AJAX
- Custom meta box is not displaying value showing tag as empty
- how to use auth_redirect() redirect visitor to login page if they are not login when they click account and order page?
- PHP/CSS: Shortcode won’t display correctly, and only displays in the head (before content)
- All categories options or All categories not Populating
- WordPress load javascript file if something… (after the page is loaded)
- Add class for the_post_thumbnail_caption()
- Getting page / post URL on publish and / or update
- Wrapping shortcode content in a span or link
- Weird Behaviour: Not all WordPress Posts appearing
- Permission functions within wordpress
- Adding ID to a Listing but not inside WP_Query while
- WordPress display name string manipulation
- 2 small questions: How to redirect to a created page & show that pages title in wp, bp
- How do I call comments_template(); from a plugin file?
- which table updated after logout?
- Accessing WordPress Functions get_permalink() in Vanilla PHP?
- How to return a Boolean for a page that is a subpage thru its name?
- Saving User Input to PHP Variable
- Undefined variable notice [closed]