html - 设置基本路径会破坏锚链接
问题描述
我创建了一个 WordPress 主题,其中的图像全部损坏,因此我在页面中添加了一个基本路径标签。
<base href="https://www.example.com/wp/wp-content/themes/my-theme/"/>
但是现在所有的锚/链接都不起作用。
<a href="#an_id_on_the_page">click here</a>
上面的链接指向“ https://www.example.com/wp/wp-content/themes/my-theme/index.php#an_id_on_the_page ”而不是同一页面,但更下方。
WordPress 建议将“”添加到每个图像的路径中。但这意味着打破工作流程并在每次更改时编辑 HTML 代码。
有什么想法可以解决这个问题吗?
更新
看起来如果我在锚前面放一个“/”,它看起来就像它正在工作。我将对其进行更多测试以确认。
解决方案
除非明确指出,否则任何链接、命名锚点或空白 href 都不会指向原始子目录:基本标记使所有链接都不同,包括指向基本标记 url 的同一页面锚链接,例如:
<a href='#top-of-page' title='Some title'>A link to the top of the page via a named anchor</a>
becomes
<a href='http://www.example.com/other-subdirectory/#top-of-page' title='Some title'>A link to an #named-anchor on the completely different base page</a>
<a href='?update=1' title='Some title'>A link to this page</a>
becomes
<a href='http://www.example.com/other-subdirectory/?update=1' title='Some title'>A link to the base tag's page instead</a>
通过一些工作,您可以通过明确指定这些链接链接到它们所在的页面来解决您可以控制的链接上的这些问题,但是当您将第三方库添加到依赖于标准行为的组合中时,它很容易造成大混乱。
资源,
推荐阅读
- c# - lib/SplashKit.cs(15240,3):错误 CS1022:类型或命名空间定义,或预期文件结尾
- javascript - 自定义元素上的 connectedCallback () 不能使用 forEach 在 javascript 上循环数据
- sql - 如何在 plpgsql 中多次创建临时表?
- flutter - 在 Flutter 中运行 HTML 代码
- python - 如何修复代码中的无效语法错误?
- c# - 在 iOS 上的家庭应用程序中将 Windows pc 的锁定状态显示为磁贴
- mysql - 对具有相同属性的两个条件使用 sum
- kubernetes - 掌舵不创造资源
- flutter - 你如何在 dart 中执行抽象类的继承?错误:超类 SpanishData 没有零参数构造函数
- azure-devops-server-2019 - 如何设置离线 Azure DevOps 源?