Im using a plugin that add comments to iframes that isn't responsive, so I would like to turn off the plugin in mobile view. How do I target the plugin for that? when I googled around this seemed to be the answer, but not sure how to target my plugin.
if (!wp_is_mobile()) {
}
I don't think disabling the plugin would be a solution in your case, because plugins are not customized to enabled and disabled for specific view.
Better idea would be to create a function in your function.php file and fire it when comment is loaded and just ignore when user is viewing in mobile else load the comments in iframe.
Can't proceed further with your given information.
Related
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:
Other theme:
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.
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.
I have a Wordpress network with a big amount of different themes and even more pages using those themes.
Now, I have a PHP function (for some tracking) that I want to run every time a page from my network is accessed. I don't want to edit all my themes, so I am looking for a central file where I can have this new function.
First thing in my mind was the index.php in the root folder of the WP installation. This would probalby work but does not seem the finest solution.
All my themes are using the wp_head function maybe this can help somehow?
Is there any other place where I can add my tracking code and make sure that it is run on every page access?
You should create a plugin to do this. In that plugin you will have that function and add the action to the wp_head hook. This will keep it working with all of your themes and easy to change without having to go into all your themes.
The code will look something like this
/**
* Plugin Name: Tracking Function
* Description: Lets me track my code
*/
function tracking_function(){
//enter code here
}
add_action("wp_head","tracking_function");
Then, because you have a network of sites, you will have to go into the Network Plugin manager, and activate the plugin for all networks and then you can activate or deactivate it for each specific site in your network.
The two options I can think of would be to use a plugin that loads "custom functions" for the sites that it is included on - much like functions.php in your theme, but independent of each theme. I wrote a plugin that does this which you can find here: http://justinsilver.com/technology/wordpress/wordpress-plugins/wordpress-plugin-custom-functions-php/
The other option would be to put a PHP file with your code into the wp-content/mu-plugins (Must-Use Plugins) that will be loaded before all other plugins on every site in your network. A bit more straightforward than the first option, but you can't selectively disable it should you not want on it on one of your network sites.
I am building a plugin for the first time and I have setup my rewrite rules to call a PHP file I have located in my plugin folder and this is working but all I have it output just now is "test"
I wanted to ask, is there is a way of pulling in the existing theme and using this as the basis for the page, then I can have my plugin just output the page content area so to speak.
My plugin is quite big in terms of the amount of data it handles so I would like to be able to use a menu link to the aforementioned file and this file can then output all the sub pages of content but still using the default theme (theme I have made) and fill the content area only is this possible and if so is there anything to explain this already available because I couldn't see it.
Any help with this would be much appreciated.
Edit: I have tried including a file from my current theme but this will give me a 500 error so I assume its not as simple as this.
Have you thought about using custom post types for your plugin content rather than relying on custom tables and separate code?
Other than that, you could use a shortcode (just one) and have users insert that into a regular WP page, the shortcode then displays all of your various plugin stuff.
It's hard to be more specific without understanding why you've done it this way.
I am new into WP Plugin development. I want to make a plugin which adds the facility to use any custom code within editor to render it into something else. For instance if I am referring my Hacker News profie and I am using the code H(HackerNewsID) then after publishing it makes a URL of Hacker News pointing to my profile.
What feature of WP would be best fit for it?
Thanks
You cand try shortcodes http://codex.wordpress.org/Shortcode_API
I found some plugins like WP Mobile Pack, but I want to put together my own very simple theme switcher. (Just don't want any bloat.)
I have a regular WordPress theme and I also created a WordPress Mobile theme as well. These are both standard WP themes that can be activated in the dashboard.
How can I direct certain user agents directly to the mobile theme? (I don't want a mobile domain, sub-domain, or trailing directory.) www.example.com should be the domain for any visitor.
The one catch is, I also want to offer a link to let users switch back. For instance, iOS devices should go to the Mobile Theme. But if they are on the large iPad, they may want to simply use the regular site. Having some sort of cookie override the default .htaccess or PHP redirection would be useful.
Any help, specifically targeted at WP and handling WP theme switching would be truly appreciated.
I would use 2 stylesheets to theme the page, and detect the browser and serve up the right css depending on what the browser is detected as. Have a look at the 'get_browser' function of PHP http://php.net/manual/en/function.get-browser.php
then just have an if statement:
if (preg_match('/mobile/i', $u_agent)) {
$css = 'mobile.css';
}
and then just load the $css
Hope that makes some sense.
You will have to create a plugin, that fires the switch theme action. Here is a reference:
https://codex.wordpress.org/Function_Reference/switch_theme
I think you can try the 'after_setup_theme' hook.