手动将插件插入 WordPress 页面
我在 worpress 头版工作。
我想手动将插件添加到页面的特定位置,但自己将代码添加到页面。
我基本上想在某个位置的某个页面中包含一个插件。所以我创建了一个 div...
<div id="plugin-holder">
**Plugin-will-appear-here-with-this-code**
</div>
没有人知道这是如何完成的吗?
谢谢
I am working in worpress front page.
I want to add a plugin to the page at a specific location manually but adding the code to the page myself.
I basically want to include a plugin in a certain page on a certain location. So I'm create a div...
<div id="plugin-holder">
**Plugin-will-appear-here-with-this-code**
</div>
Don't anyone know how this is done please?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您希望插件出现在某个地方,您将寻找“短代码”功能。
这实际上非常容易编码,请查看 Codex 中 Shortcode API 下的示例 - 即:
一次您已经调用了这些函数,您可以在代码中使用 [bartag],它将运行您的函数并用函数返回的生成文本替换短代码。
如果您要向网站添加短代码功能,通常最有意义的是编写一个非常简单的插件并将其放入其中。这样做效果最好的原因是,随着时间的推移,很容易忘记并错误地升级主题(甚至更改为新主题),从而通过丢失以前的functions.php中的自定义代码来破坏您的网站。令人惊讶的是,这非常容易实现,只需要在插件文件顶部添加一些特殊格式的注释和一些编码常识 - 有很多教程和“如何”!
这是一个有用的短代码教程:http://www.really effective.co.uk/archives/2009/06/22/how-to-code-your-own-wordpress-shortcode-plugin-tutorial-part -1/
If you're wanting a plugin to appear somewhere, you'll be looking for "shortcode" functionality.
This is actually surprisingly easy to code, check out the examples in the Codex under Shortcode API - ie:
Once you've called these functions you can use [bartag] in code and it will run your function and replace the shortcode with the generated text your function returns.
If you're adding shortcode functionality to your site, it generally makes most sense to code a really simple plugin and put it in that. The reason why this works best is that, over time, it's really easy to forget and upgrade a theme by mistake (or even change to a new theme) and thus break your site by losing your custom code in your former functions.php. Surprisingly, this is pretty easy to achieve and only requires some specially formatted comments at the top of your plugin file and a little common sense in coding - there are many tutorials and "how to"s around!
Here's a useful shortcode tutorial: http://www.reallyeffective.co.uk/archives/2009/06/22/how-to-code-your-own-wordpress-shortcode-plugin-tutorial-part-1/
您应该将相关插件代码添加到
functions.php
中。我怀疑您会想要使用一些 条件标记,例如
is_home()
来精确定位您的位置。但也许不是,具体取决于您想要执行的操作,此外,如果您尝试从预先存在的插件中插入,请确保删除
register_activation_hook
或activate_pluginname
行动。You should add the relevant plugin code to
functions.php
.I suspect you'll want to use some conditional tags, like
is_home()
to pinpoint your location. But maybe not, depending on what you are trying to do,Also, if you're trying to to insert from a pre-existing plug-in, make sure you remove the
register_activation_hook
oractivate_pluginname
action.如果你的插件支持侧边栏小部件,你可以简单地“widgitize”你想要插入插件的 div 标签。谷歌这个术语,你会找到很多资源。
If your plugin supports a sidebar widget you can simply "widgitize" the div tag that you wish to insert the plugin into.. Google the term and you are gonna find many resources.