将 php 元素添加到 WordPress 中的自定义页面
我正在尝试自定义 WordPress 页面以包含 iframe,该 iframe 为用户提供下载链接。我们使用 WordPress 2.9.2 和论文主题 1.51。我一直在尝试使用论文挂钩,但似乎 php 已从输出中删除。帮助?建议的替代方案?
来自custom_functions.php的代码:
function add_ejunkie_download_link () {
is_page('slug-url-of-page') {
?>
<?php
echo '<iframe src="https://www.e-junkie.com/ecom/rp.php?noredirect=true&client_id=CID&txn_id=' . htmlspecialchars($_GET["txn_id"]) . '" width="100%" frameborder="0" height="50px"></iframe>';
?>
<?php
}
}
remove_action('thesis_hook_custom_template', 'thesis_hook_custom_template');
add_action('thesis_hook_custom_template', 'add_ejunkie_download_link');
I'm trying to customize a wordpress page to include an iframe which give the users a link to there download. We're using wordpress 2.9.2 with the Thesis theme 1.51. I've been trying to use thesis hooks but appears that the php is stripped from the output. Help? Suggested alternatives?
Code from custom_functions.php:
function add_ejunkie_download_link () {
is_page('slug-url-of-page') {
?>
<?php
echo '<iframe src="https://www.e-junkie.com/ecom/rp.php?noredirect=true&client_id=CID&txn_id=' . htmlspecialchars($_GET["txn_id"]) . '" width="100%" frameborder="0" height="50px"></iframe>';
?>
<?php
}
}
remove_action('thesis_hook_custom_template', 'thesis_hook_custom_template');
add_action('thesis_hook_custom_template', 'add_ejunkie_download_link');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然不如 custom_functions.php 中的自定义钩子那么优雅,但论文 Open Hook WordPress › 论文 OpenHook « WordPress插件是添加带有可执行代码的挂钩的简单方法。
Though not as elegant as custom hook in custom_functions.php, Thesis Open Hook WordPress › Thesis OpenHook « WordPress Plugins is an easy way to add hooks with executable code in them.
为什么要调用
remove_action
?我真的不认为你需要它。PHP 无法从输出中删除,因为它只是... PHP。它是在运行时解析的,因此不会被剥离,而是被执行。
我猜您只想在 Thesis 调用
thesis_hook_custom_template
挂钩时打印iframe
?你是否仔细检查过这个钩子实际上被调用了,并且它在你期望的地方被调用了?
然后尝试用这个来简化你的挂钩函数;
Why the
remove_action
call? I really don't think you need it.The PHP can't be stripped from the output, because it's just that... PHP. It's parsed at runtime, so it's not stripped, it's executed.
I'm guessing you just want to print the
iframe
when Thesis calls thethesis_hook_custom_template
hook?Have you double checked this hook is actually getting called, and that it's getting called where you expect it to?
Then try simplifying your hooked function with this;