Warning: Illegal string offset 'top' in /www/wwwroot/hellyhua.com/wp-content/themes/Snape/single.php on line 45

WordPress强大之处就是在于,我们能想到的已经实现了,只是我们不知道而已。

网上有很多解决方案,基本归类为:

1. 通过Rewrite Rule 301跳转实现(如果是已经被收录的URL可以的,但刚开始时不建议使用)

2. 通过修改wp-includes/canonical.php实现(升级时会被覆盖,不建议)

3. 通过插件来实现

下面就说一下插件方法:

插件 Permalink Trailing Slash Fixer 已经实现这个功能。

下载后查看代码,你会发现只有几行而已。 而且内部调用的是Wordpress自带的方法实现的。 并且不会出现301跳转。 个人认为非常理想的解决方案。

/** * Public staff only. */ if (is_admin()) return;$permalink_structure = get_option('permalink_structure'); if (!$permalink_structure || '/' === substr($permalink_structure, -1))  return;add_filter('user_trailingslashit', 'ppm_fixe_trailingslash', 10, 2); /** * Appends a trailing slash if it's missing in the permalink structure. * * Conditionally adds a trailing slash if the url type is not "single". * * @param string $url A URL with or without a trailing slash. * @param string $type The type of URL being considered (e.g. single, category, etc). * @return string The URL with the trailing slash fixed. */ function ppm_fixe_trailingslash($url, $type){  if ('single' === $type)   return $url;  return trailingslashit($url);}

Warning: Illegal string offset 'footer' in /www/wwwroot/hellyhua.com/wp-content/themes/Snape/single.php on line 49