最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Getting an error. Need to add favicon in my child theme functions.php. What's wrong?

programmeradmin1浏览0评论

When I put this code in my functions.php

add_action('wp_head', 'my_favicon');
function my_favicon() {
    echo "<link rel='shortcut icon' href=' " . get_stylesheet_directory_uri() .
         '/images/favicon.ico'"'>";
}

I get

[Message from webpage]: There has been a critical error on this website. Learn more about debugging in WordPress.

What's wrong with my code?

When I put this code in my functions.php

add_action('wp_head', 'my_favicon');
function my_favicon() {
    echo "<link rel='shortcut icon' href=' " . get_stylesheet_directory_uri() .
         '/images/favicon.ico'"'>";
}

I get

[Message from webpage]: There has been a critical error on this website. Learn more about debugging in WordPress.

What's wrong with my code?

Share Improve this question edited Feb 15, 2021 at 0:52 Rup 4,4004 gold badges29 silver badges29 bronze badges asked Feb 15, 2021 at 0:06 Jerry FleurivalJerry Fleurival 32 bronze badges 8
  • 1 where did you add this code? what is the full text of the error message? – Michael Commented Feb 15, 2021 at 0:27
  • @Michael The error was when a reload the webpage. [Message from webpage]: There has been a critical error on this website. Learn more about debugging in WordPress. I put this line of code in my functions.php. code **add_action('wp_head', 'my_favicon'); function my_favicon() { // echo "<link rel='shortcut icon' href=' " . get_stylesheet_directory_uri() . '/images/favicon.ico'"'>"; } ** code – Jerry Fleurival Commented Feb 15, 2021 at 0:30
  • 1 You've got a syntax error: that '/images/favicon.ico'"' should be "'/images/favicon.ico'. And the href should have no whitespace at the beginning, so use href='". – Sally CJ Commented Feb 15, 2021 at 0:39
  • 1 Sorry @JerryFleurival, I meant, "/images. But why don't you just use the Customizer → Site Identity → Site Icon to set the site icon (or favicon)? – Sally CJ Commented Feb 15, 2021 at 1:42
  • 1 @SallyCJ Awesome that fixed it. Thank you so much. Muneeb solved it too. I'm aware of using Customizer. I'm just a person who likes to know everything under the hood.
发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>