简体   繁体   English

wordpress:我可以避免在<href标签内将“<”和“>”转换为“<:”和“>”

[英]wordpress: Can I avoid “<” and “>” being converted to “&lt:” and “&gt;” inside href tag

I want to add a link on my wordpress website to take the user to the wordpress default "forgot password" page. 我想在我的wordpress网站上添加一个链接,将用户带到wordpress默认的“忘记密码”页面。 Here is the wordpress documentation page I am working off of: 这是我正在处理的wordpress文档页面:

http://codex.wordpress.org/Function_Reference/wp_lostpassword_url http://codex.wordpress.org/Function_Reference/wp_lostpassword_url

I am adding the link as text in the wordpress text editor as I don't have direct access to the source files. 我在wordpress文本编辑器中添加链接作为文本,因为我没有直接访问源文件。 I am using the example html from the documentation page: 我正在使用文档页面中的示例html:

<a href="<?php echo wp_lostpassword_url(); ?>" title="Lost Password">Lost Password</a>

However, when I save the page, the "greater than" and "less than" brackets are converted to their respective html encoding so on the site instead of displaying the url as the href value, the string literal "<?php echo wp_lostpassword_url(); ?>" is displayed. 但是,当我保存页面时,“大于”和“小于”括号将转换为它们各自的html编码,因此在网站上而不是将url显示为href值,字符串文字"<?php echo wp_lostpassword_url(); ?>"显示。

How can I avoid that? 我怎么能避免这种情况?

Wordpress will not parse PHP code. Wordpress不会解析PHP代码。 There are plugins that can do it if you desire, but they are less than optimal. 如果您愿意,可以使用插件,但它们不是最佳的。 Instead, try something like this... 相反,尝试这样的事情......

In your functions.php file: 在你的functions.php文件中:

add_shortcode('lostpassword_url', 'my_lostpassword_url');

function my_lostpassword_url($atts){
    return wp_lostpassword_url();
}

In the page with your form: 在包含您表单的页面中:

<a href="[lostpassword_url]" title="Lost Password">Lost Password</a>

This will tell WordPress to parse the content of your page/post and replace the [lostpassword_url] with the function call. 这将告诉WordPress解析您的页面/帖子的内容,并用函数调用替换[lostpassword_url]。

It's not beautiful, it's not fancy, I have no proud of that, but it just work: 它并不美丽,它并不华丽,我对此并不感到自豪,但它只是起作用:

function callback($buffer) {
    $buffer = str_replace('&amp;','&',$buffer);
    $buffer = str_replace('&gt;','>',$buffer);
    $buffer = str_replace('&quot;','"',$buffer);
    $buffer = str_replace('&lt;','<',$buffer);
    return $buffer;
}
function buffer_start() { ob_start("callback"); }
function buffer_end() { ob_end_flush(); }
add_action('wp_head', 'buffer_start');
add_action('wp_footer', 'buffer_end');

That's the only solution worked when displaying PHP code on my posts. 这是在我的帖子上显示PHP代码时唯一有效的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 正则表达式将html标记中的&lt;或&gt;替换为&gt;或&lt; - Regex to replace < or > with &gt; or &lt; inside html tag 在WordPress中过滤短代码时过滤&lt;!-nextpage-&gt;标签 - Filter &lt;!--nextpage--&gt; tag while filtering shortcode in WordPress 如果条件在href标签中怎么写? - How can i write this if condition inside the href tag? 如何正则表达式&lt;和&gt;替换标签中的&lt;和&gt; <code> </code> ? - how to regex character < and > replace like &lt; and &gt; in tag <code> </code>? 当我导航到http://example.com/test.php时,为什么$ _GET [&#39;name&#39;]是Nothing?&lt;&lt;&lt; Apple &gt;&gt;&gt; - why does $_GET['name'] is Nothing, when i navigate to http://example.com/test.php?&lt;&lt;&lt;Apple&gt;&gt;&gt; 剥离标签(&lt;和&gt;) - Strip tags (&lt; and &gt;) 替换rawurlencode中的entites即&lt;&gt;“ - replace entites in rawurlencode i.e. &lt; &gt; &quot; 如何从数据库导出值并回显所有用&lt;hr /&gt;隔开的值,除了第一个和最后一个结果? - How can I export values from a database and echo all it separated by an &lt;hr /&gt;, except the first and the last results? 我可以在htaccess中修改定位标记href吗? - Can I modify anchor tag href in htaccess? 我怎样才能将 append 地址<a>标记为 href</a> - How can I append address to <a> tag href
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM