手动将插件插入 wordpress 页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6125172/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:46:17  来源:igfitidea点击:

Insert a plugin manually into wordpress page

wordpress-pluginwordpress-themingwordpress

提问by Satch3000

I am working in worpress front page.

我在 worpress 头版工作。

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...

<div id="plugin-holder">
     **Plugin-will-appear-here-with-this-code**
</div>

Don't anyone know how this is done please?

请问有人知道这是怎么做的吗?

Thanks

谢谢

采纳答案by two7s_clash

You should add the relevant plugin code to functions.php.

您应该将相关的插件代码添加到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,

我怀疑你会想要使用一些条件标签,比如is_home()确定你的位置。但也许不是,这取决于你想做什么,

Also, if you're trying to to insert from a pre-existing plug-in, make sure you remove the register_activation_hookor activate_pluginnameaction.

此外,如果您尝试从预先存在的插件插入,请确保删除register_activation_hookactivate_pluginname操作。

回答by Brian C

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:

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

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.

一旦你调用了这些函数,你就可以在代码中使用 [bartag] ,它会运行你的函数并用你的函数返回的生成文本替换短代码。

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!

如果您要向站点添加短代码功能,通常最有意义的是编写一个非常简单的插件并将其放入其中。这样做效果最好的原因是,随着时间的推移,很容易忘记并错误地升级主题(甚至更改为新主题),从而通过丢失以前的functions.php 中的自定义代码而破坏您的站点。令人惊讶的是,这很容易实现,只需要在插件文件顶部添加一些特殊格式的注释和一些编码常识 - 有很多教程和“如何”!

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/

这是一个有用的短代码教程:http: //www.reallyeffective.co.uk/archives/2009/06/22/how-to-code-your-own-wordpress-shortcode-plugin-tutorial-part-1/

回答by Noura Mahmoud Alhashash

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.

如果你的插件支持侧边栏小部件,你可以简单地“widgitize”你希望插入插件的 div 标签。谷歌这个词,你会找到很多资源。