将 php 元素添加到 WordPress 中的自定义页面

发布于 2024-09-04 06:44:38 字数 664 浏览 10 评论 0原文

我正在尝试自定义 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

把人绕傻吧 2024-09-11 06:44:38

虽然不如 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.

如歌彻婉言 2024-09-11 06:44:38

为什么要调用 remove_action ?我真的不认为你需要它。

PHP 无法从输出中删除,因为它只是... PHP。它是在运行时解析的,因此不会被剥离,而是被执行。

我猜您只想在 Thesis 调用 thesis_hook_custom_template 挂钩时打印 iframe

你是否仔细检查过这个钩子实际上被调用了,并且它在你期望的地方被调用了?

然后尝试用这个来简化你的挂钩函数;

 function add_ejunkie_download_link() {
     if (is_page('slug-url-of-page')):
 ?>

 <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
     endif;
 }

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 the thesis_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;

 function add_ejunkie_download_link() {
     if (is_page('slug-url-of-page')):
 ?>

 <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
     endif;
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文