[英]wordpress: Can I avoid “<” and “>” being converted to “<:” and “>” 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('&','&',$buffer);
$buffer = str_replace('>','>',$buffer);
$buffer = str_replace('"','"',$buffer);
$buffer = str_replace('<','<',$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.