I get this notice when debugging my new site.

Does anybody know what this means? It doesn't break the site but it's just a warning when I switch debug mode on and I would like to solve this issue.

This Notice only shows up when the comments option is available. When you a single post page and the comments have been closed through the dashboard this notice doesn't show up.

This is the 'error' I get:

NOTICE: wp-includes/comment-template.php:26 - Trying to get property of non-object

require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/XXX/my-templates/template-home.php'), get_footer, locate_template, load_template, require_once('/themes/XXX/footer.php'), wp_footer, do_action('wp_footer'), call_user_func_array, wp_admin_bar_render, do_action_ref_array, call_user_func_array, wp_admin_bar_my_account_item, get_avatar, apply_filters('get_avatar'), call_user_func_array, XXX_remove_dimensions_avatars, get_comment_author

  • I'd guess your theme (in "footer.php"?) is calling get_comment_author() without checking for have_comments() first... – bonger Dec 20 '14 at 17:51
  • Syntax errors are off-topic on this site. <a href="wordpress.stackexchange.com/help/on-topic">See the help center</a>. – cybmeta Dec 20 '14 at 18:58
  • 1
    Thank you @bonger - you're very helpful! I had used the get_comment_author() function to place the name of the author on the img alt attribute. – Jack Ottermans Dec 20 '14 at 21:06
  • @bonger as an answer please :) – Rarst Dec 21 '14 at 12:07
up vote 1 down vote accepted

Per comments, you need to check for have_comments() first, before using any of the comment-template functions such as get_comment_author(), otherwise they try to call methods on a null comment object, producing PHP warnings.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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