如何在WordPress中拦截Banner?

发布于 2024-08-27 12:16:45 字数 329 浏览 1 评论 0原文

我的客户希望我制作一个插件,拦截 WordPress 博客上的横幅,以便显示现有横幅,但在其正下方、内容和侧边栏上方,会出现另一个横幅。他需要它适用于大多数主题,而不是特定于主题。

我发现我可以使用 add_action('loop_start','interceptMe') 在帖子或单个帖子之前将一些内容放在顶部,但它仍然将侧边栏留在右侧。我尝试过使用 add_action('all','test') 转储不同的拦截,看看我是否能弄清楚这一点,但我似乎还无法得到它。我想我可能必须拦截所有 esc_html 调用并根据上下文进行检查,直到找到用于横幅的调用。

有谁知道如何拦截横幅以在其下方添加另一个横幅?

My client wants me to make a plugin that intercepts the banner on a WordPress blog so that the existing one displays, but right beneath it, above the content and the sidebar, another banner appears. And he needs it such that it works in most themes and isn't theme-specific.

I found I could use add_action('loop_start','interceptMe') to put something at the top before posts or a single post, but it still left the sidebar on the right. I have tried using add_action('all','test') to dump out different intercepts to see if I could figure this out, but I just can't seem to get it yet. I'm thinking I may have to intercept all esc_html calls and contextually inspect that until I find one used for the banner.

Does anyone know how to intercept the banner to add another one right beneath it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

寂寞笑我太脆弱 2024-09-03 12:16:45

这将是非常具有挑战性的。没有一致的结构、HTML 或 CSS ID 允许您像这样进行跨主题注入(天啊,有些主题没有标题图像)。为此,您可能需要对每个主题进行手动更改。

This is going to be very challenging to do. There's no consistent structure, HTML, or CSS IDs that would allow you to do cross-theme injection like this (hell, some themes don't have a header image). You will likely need to make manual changes to each theme for this.

因为看清所以看轻 2024-09-03 12:16:45

我想您可能会插入一些 JavaScript 来查找 H1 标签并在其后面插入您的横幅。不过,Ceejayoz 是对的——不同的主题并不一致。一个主题可能使用 H1 作为网站标题,另一个主题可能使用 H1 作为帖子标题。

I suppose you might insert some JavaScript that looks for an H1 tag and inserts your banner right after it. Ceejayoz is right though -- there's not consistency to different themes. One theme might use H1 for the site header and another for a Post title.

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