You don’t check anywhere that you’re viewing a comment when you use get_comment_author();
. The get_avatar()
function is used in a lot of places in WordPress; your code seems to assume it’s only in use on comments.
Try this (the code is untested, but should work, I think):
add_filter( 'get_avatar' , 'alt_name_avatar');
function alt_name_avatar( $avatar ) {
if ( null === get_comment() ) {
// This isn't a comment.
return $avatar;
}
$alt = get_comment_author();
$avatar = str_replace('alt=\'\'','alt=\'Avatar for '.$alt.'\' title=\'Avatar for '.$alt.'\'',$avatar);
return $avatar;
}
There doesn’t seem to be a simple is_comment()
check to see if we’re viewing a comment, so I’ve chosen to test get_comment()
, which will return null
if we’re not in a comment.
Related Posts:
- Can i use php sql functions instead of $wpdb?
- Why include a composer.json file with my plugin?
- Getting paginate_links() ‘end_size’ to display none
- Customize default settings on new sites on multisite
- wp_delete_auto_drafts() deletes links in menus
- What is the best practice for escaping data URIs?
- Question about repurposing WordPress 404 handler
- append PHP function to the_content
- Setting up the child theme so as to enable right-to-left WordPress?
- How to track a users progress through pages by inserting data into WordPress Database?
- How do I get content of custom post type through post ID in wordpress
- Hooking new functions to actions + passing parameters
- How to display blog images using wordpress in existing project
- Block PHP Files Nginx
- “The plugin generated 2694 characters of unexpected output…” on Plugin activation, CREATE TABLE sql command not working
- mysqli_real_connect() – authentication method unknown to the client Warnings
- how to increase custom post value by one most efficiently?
- WordPress File handle – fopen, fwrite not working with $.ajax or $.post Jquery
- Do I need to prepare query before get_results(), get_row() and get_var()?
- WooCommerce: Add Payment Gateway Field to Webhooks [closed]
- Woocommerce product download URL
- Multiple choice in a custom taxonomy
- Calculations in functions.php [closed]
- Parsing php string in jquery [closed]
- How does the ternary operator work in the wordpress loop post?
- How to create a linked tag list in my sidebar
- WordPress custom login form using Ajax
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- How to store post ID’s in cookie or session to display the same posts later
- Dynamic content in template
- register_taxonomy() take much queries
- Whats the proper way to use a php stylesheet in a wordpress theme? [duplicate]
- Limit checklist by the current user
- Adding Meta Tags to a Post using its Tags, Excerpt and content
- Embedding PHP in shortcode $content
- single.php with different look by category
- WordPress Block developer from exporting Database via PHP
- Is There A Way To Make Theme Files Accept Shortcodes?
- Is there any way to get a drop down list of time zones?
- php within html within php
- Changing the color scheme based on the url visited
- Clickable image link sends people to wrong URL
- Plugin development and composer
- WC_Customer delete function returns error
- Increment paged on WP_Query
- Trying to display text in a block in a plugin page
- Some menu items wont budge
- Issue replacing forward slash in string
- Removing “Powered by” footer using child theme PHP [closed]
- custom post type with role Vendor
- Store and Change Session variable – PHP SESSION VARIABLE
- Show site content based on user role
- Cannot load media and I get “PHP Warning: Invalid argument supplied for foreach(“
- Adding “redirect” to a button
- PHP Parse error on WP-CLI, not on web server
- Get the id of the row from database on click of a button [closed]
- Trying to split a query into sections of six
- Execute Jquery when a specific page in my plugin is loading
- Modifying WP URL handing code?
- Show ranking based on post id
- Validating an email input from form field before submit using JQuery, AJAX, and PHP
- url not using query string no longer working
- How do I reopen the (Popup Maker) after entering the correct password for a password protected page?
- Display div if category has a specific parent
- Display metabox galleries on specific page template in admin editor
- I want it to detect the duplicate comment and give a warning on the same page
- Inside Array – “unidentified index” error with “prepare was called incorrectly” despite not calling the prepared statement with wordpress [closed]
- How to identify which php file a plugin is using on page load?
- dashboard widget form not submit mails
- How to switch between two primary menus (programatically0
- Why am I getting syntax error, unexpected ‘endwhile’ (T_ENDWHILE) on single.php
- How to show category just on specific pages?
- Used a code to revoke some dashboard menus for my contributors but for some reason it’s revoked me access to the editor [closed]
- How do I get the value of a current user’s custom field?
- If is_page elseif is_page not working like I want it to
- Allow Comments by Default for Multiple Post Types
- HELP! Frontend User Profile Edit Won’t Update Email
- I want show only data for today
- Make customizer panel or section button
- How can I customize a WordPress theme before it’s downloaded?
- Permalinks and custom PHP application
- Updating meta_value in a custom key
- Where to find the html for WordPress site? [closed]
- rewrite_rule – working fine but broken for pagination
- Custom post type single page return to listing page
- WordPress wp_remote_post() sending informaiton to Redmine REST API
- WordPress rewrite question
- Using Nonce for my Form
- Transient Loop Not working as expected
- How to declare a variable at the bottom of the page and use its value at the top?
- Shortcode working in page.php but not in category.php in wordpress
- Open all external links in new window – need help with the code
- ACF: Echo page title when checkbox is checked
- How can a ‘scripts’ directory be hooked into wp_head();?
- HTML in PHP problem [closed]
- rest_cannot_create_user – Sorry, you are not allowed to create new users. CURL WORDPRESS REST API
- Cannot install plugins or themes on new WordPress installation at Cloudways
- links Slick jS library using wp_enqueue_scripts not pulling
- How to run site locally after downloading database
- How to change shipping method title based on cart amount?