URL 中的 wordpress 和硬编码域名 [英] wordpress and hardcoded domain names in URL

查看:31
本文介绍了URL 中的 wordpress 和硬编码域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装了 Wordpress,我发现的一件事是站点 URL 似乎在所有生成的 HTML 中进行了硬编码.

I just installed Wordpress, and one thing I discovered is that site URL appears to be hardcoded in all the generated HTML.

例如,我看到以下内容:

For example, I see things like:

<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="stylesheet" type="text/css" media="all" href="http://www.mywebserver.com/wp-    content/themes/twentyeleven/style.css" />
<link rel="pingback" href="http://www.mywebserver.com/xmlrpc.php" />

有没有办法告诉 Wordpress 在生成的 URL 中去掉域名?例如,我更喜欢:

Is there a way to tell Wordpress to strip out the domain name in the generated URLs? For example, I would prefer:

<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="stylesheet" type="text/css" media="all" href="/wp-content/themes/twentyeleven/style.css" />
<link rel="pingback" href="/xmlrpc.php" />

推荐答案

几个代码链接可以修复它,在你的函数文件和头文件中:修复 Wordpress 中的绝对链接

A couple links of code can fix it, in your functions file and header file: Fix absolute links in Wordpress

Functions.php

function fix_links($input) {
return preg_replace('!http(s)?://' . $_SERVER['SERVER_NAME'] . '/!', '/', $input);
}

Header.php -- 在您输出任何 HTML 之前

Header.php -- before you output any HTML

ob_start('fix_links');

这篇关于URL 中的 wordpress 和硬编码域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆