dongluyi5123
dongluyi5123
2016-04-04 08:41

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

已采纳

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 duanfengtuo6012 5年前

    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.

    点赞 评论 复制链接分享

相关推荐