wordpress and hardcoded domain names in URL

2019-05-06 06:10发布

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" />

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
1条回答
别忘想泡老子
2楼-- · 2019-05-06 06:26

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 -- before you output any HTML

ob_start('fix_links');
查看更多
登录 后发表回答