手动将插件插入 WordPress 页面

发布于 2024-11-10 05:55:03 字数 262 浏览 1 评论 0原文

我在 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 技术交流群。

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

发布评论

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

评论(3

飘落散花 2024-11-17 05:55:03

如果您希望插件出现在某个地方,您将寻找“短代码”功能。

这实际上非常容易编码,请查看 Codex 中 Shortcode API 下的示例 - 即:

function bartag_func( $atts ) {
    // ... do more things here ...
return "text to replace shortcode";
}
add_shortcode( 'bartag', 'bartag_func' );

一次您已经调用了这些函数,您可以在代码中使用 [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:

function bartag_func( $atts ) {
    // ... do more things here ...
return "text to replace shortcode";
}
add_shortcode( 'bartag', 'bartag_func' );

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/

谈场末日恋爱 2024-11-17 05:55:03

您应该将相关插件代码添加到functions.php中。

我怀疑您会想要使用一些 条件标记,例如 is_home()来精确定位您的位置。但也许不是,具体取决于您想要执行的操作,

此外,如果您尝试从预先存在的插件中插入,请确保删除 register_activation_hookactivate_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 or activate_pluginname action.

森末i 2024-11-17 05:55:03

如果你的插件支持侧边栏小部件,你可以简单地“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.

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