WordPress在主体标记后直接钩 [英] WordPress hook directly after body tag

查看:104
本文介绍了WordPress在主体标记后直接钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找适合我的插件使用的钩子时遇到了问题.我正在尝试通过让我的插件添加功能来在每页顶部添加一条消息.最好使用什么钩子?我想在<body>标签之后插入内容.

I'm having problems finding the right hook to use for my plugin. I'm trying to add a message to the top of each page by having my plugin add a function. What's the best hook to use? I want to insert content right after the <body> tag.

我知道现在已经三年了,但这是一张 Trac 的门票任何有兴趣的人: http://core.trac.wordpress.org/ticket/12563

I know it's three years later now, but here is a Trac ticket for anyone who is interested: http://core.trac.wordpress.org/ticket/12563

2019年7月31日

链接的 Trac票证已关闭,因为此功能已在WordPress 5.2中添加.您可以在此处找到此功能的开发人员说明(需要启用JavaScript才能显示):

The linked Trac Ticket was closed as this feature was added in WordPress 5.2. You will find the Developer notes for this feature here (requires JavaScript enabled to display):

其他5.2中的开发人员更新

出于历史原因,我不会将正确答案"更新为提到5.2的答案,但是请放心,我知道并且内置钩子是使用的正确答案.

I will not update the "correct answer" to one that mentions 5.2 for historical reasons, but rest assured that I'm aware and that the built-in hook is the correct one to use.

推荐答案

WordPress 5.2或更高版本:

使用 wp_body_open 钩子.

有点困难...大多数主题在该区域都没有任何关联.您可以将javascript/html解决方案连接到wp_footer并将其显示在页面顶部...类似于Stack Overflow的实现方式,或者Twitter如何进行其通知.

That's kinda difficult... Most themes don't have any hooks in that area. You could hook a javascript/html solution into wp_footer and display it at the top of the page... sort of how Stack Overflow does it, or how Twitter does their notifications.

这是WordPress中包含的所有挂钩的最佳参考: http://adambrown.info/p/wp_hooks/

This is the best reference for all the hooks included in WordPress: http://adambrown.info/p/wp_hooks/

这篇关于WordPress在主体标记后直接钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆