dongluyi5123 2016-04-04 08:41
浏览 32
已采纳

主题更改后,插件在前端消失

I am developing a plugin for Woocommerce. I thought it would be nice if the plugin looked nice in different themes. So I downloaded a theme and installed and activated it.

So I checked the plugin on the product page. But it wasn't there!

I changed back to some other theme and it showed up again!

So my question is, is this my fault for developing a not-so dynamic plugin?
Or is this the fault of the theme creator?
And what are the possible explanations/solutions for those kind of problems?

Example:

Twenty fifteen:

Working

Other theme:

enter image description here

The elements of my plugin are not there as far as I've seen.

Edit

I am using the woocommerce_after_main_content hook.

Which I do like this:

add_action( 'woocommerce_after_main_content', 'ws_action_woocommerce_after_main_content', 10);

This calls my function which runs a shortcode.

Like this:

function ws_action_woocommerce_after_main_content() {

  do_shortcode('[ws_frame]');

}

This shortcode ofcourse has the function with <h1>Hello, I'm here!</h1>

Summary of how my plugin works

My plugin is a designer plugin for shirts (May aswell be for other products).

The plugin has an options page in the backend.

My plugin only gets loaded if Woocommerce is active. Also, the plugin only gets shown on the product page IF the product is in the specified category.

Using shortcodes, the front end layout is generated in a function, where some enqueued scripts and css is present. The function also has some HTML.

As mentioned above, I am using woocommerce_before_main_content hook.
This calls a function which has the do_shortcode('[ws_frame]') in it.
This shortcode as the enqueued scripts, css and has some HTML.
Yet, I do have ob_flush(); before the do_shortcode('[ws_frame]').
So this might be something?
Also, there isn't much more going on for the front end of this plugin. This is what have done to make it appear on the product page. The options page in the admin panel still works.

The question still remains, is it me, who needs to fix this, or is this something the theme creator is responsible for?
And how can I fix this myself? How can I make sure all of the hooks I'm using are still available in that theme?
Even if it is the theme's creators fault, I would like to know how I can fix this myself.

  • 写回答

1条回答 默认 最新

  • duanfengtuo6012 2016-04-04 10:42
    关注

    I may be wrong but I guess in your case the theme for which your plugin is not displayed has the particular action removed. (you may check that in the respective theme's functions file.) Well, it is better idea to hook your plugin (functionality related into some action hook which is related to functionality or which renders some funcitonality (rather than being an UI related action).

    Like, the action you have used to hook your plugin woocommerce_after_main_content along with another action, only outputs an html element wrapper. (which some themes might remove and use their custom html wrapper.

    In your case since your plugin is related to / displayed on single product page, I would recommend to use relevant action to hook your plugin. e.g. woocommerce_after_single_product_summary or woocommerce_after_single_product, which are generally not removed by woocommerce compatible themes.

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法