I am developing a WordPress theme, i have downloaded and installed the "contact form 7" plugin. Now when i send this theme to my client and they install/activate the theme, i would like the "contact form 7" plugin to be included.
I haven't got access to their wp-admin and i can't expect them to manually install the plugins. So to make it easier for them, i'd like to package the plugins with the theme. Then they install and everything works correctly.
How do i do this or is there a better way e.g. recommend installing a plugin?
You will want to use some variant of the following:
function my_activate_theme() {
$plugins = array(
"plugin_name_1",
"plugin_name_2",
"etc..."
);
foreach ($plugins as $plugin) {
$path = '/path/to/wordpress/wp-content/plugins/{$plugin}.php';
activate_plugin($path);
}
}
add_action('switch_theme', 'my_activate_themes');
You will have to fiddle around with my code, as I don't have access to a wordpress install at the moment to test on, but basically the idea is that you throw this into your functions.php file. It registers the hook for switching theme and on theme switch, loops through the specified plugins and activates them.
I hope this helps, if not, please give me more information and I will attempt to provide further guidance. Good luck!
If you are currently developing theme, you'd rather use tgm activation code than including plugins into your theme.
Please review this Wordpress Theme.
This theme use tgm activation code to install "Visual Composer","Layerslider","Revslider","Quickshop" plugins.
It's much easier to customize and has lots of features. Also easy to learn code tips.
Regards. HanaTheme.
Related
Not Working 'posts carousel' in my Wordpress website.
In my theme, the 'Posts Carousel' function is not working.
I thought it might be a plugin problem, so I can't see it even if I turn off all plugins.
But when I use the WordPress default theme, 'Posts Carousel' is worked.
All 4 plugins for 'Posts Carousel' are not worked the same.
Could you help me?
I'm so stressed out by this part, and if the deadline is approaching and I can't fix it, I have to start all the projects again.
https://knock-em.com/home-new/
I think you have an conflicts jquery
The following links can help you
jquery conflicts
Load a default WordPress script from a non-default location
jQuery noConflict wrappers
I want to override woocommerce templates from my theme. I follow all the steps from the official documents of woocommerce. And I'm sure that there is no woocommerce.php file in my theme.
So, I can;t understand why it isn't working.
I'm using twenty seven theme.
Any help will be appreciated.
I had an issue with this relating to the WooCommerce template cache.
The cache can be cleared by navigating to:
WooCommerce > Status > Tools > Clear template cache
If you've already read this documents
https://docs.woothemes.com/document/template-structure/
Please Note: When creating woocommerce.php in your theme’s folder, you will
be unable to override the woocommerce/archive-product.php custom
template in your theme, as woocommerce.php has priority over all other
template files. This is intended to prevent display issues.
Also make sure that you don’t have “Template Debug Mode” activated that you can find under:
WP Dashboard -> WooCommerce -> System Status -> Tools
Try to declare Woocommerce support in your theme's function.php
After lots of researching, finally I've found my answer from here WordPress - Failing to override woocommerce templates
Actually, I use all of my files inside the template folder and this is the reason why it didn't work.
So simple steps. But I can't understand how was I miss it!
Thank's Mo'men Mohamed for your suggetions.
Yes i agree with Mobashir.
There are three steps to check why override not working :
Check in functions.php for woocommerce supported added ( URL : https://docs.woocommerce.com/document/woocommerce-theme-developer-handbook/ )
Check spelling of directory and files is proper in theme such as your-theme/woocommerce. ( URL : https://docs.woocommerce.com/document/template-structure/ )
Woocommerce allow to change the location of woocommerce template. Hook is : woocommerce_template_path .If you are using the premium theme then check for filter hook in your theme's functions.php file. If that hook exits then use that location which is mention in that hook's callback function.
I'm facing the same issue. I am using the JupiterX theme with Elementor and trying to override the checkout template in the JupiterX Child theme, but it's not loading. I have double checked the path, it's like themes/jupiterx-child/woocommerce/checkout/form-checkout.php.
Solution:
I have resolved the issue. Actually, the JupiterX theme has its own WooCommerce overriding structure, that is themes/jupiterx/lib/templates/woocommerce/checkout/form-checkout.php and the same for the child theme that is themes/jupiterx-child/lib/templates/woocommerce/checkout/form-checkout.php.
For more details: themes.artbees.net/docs/overriding-woocommerce-templates
I am making my first steps coding. I made some courses on Internet, and now I started to make a Wordpress theme to continue learning from the practice.
I find that there is a lot of Plugins that can help me to achieve the goals that I want, and I also found a plugin that makes almost everything that I want.
I started to modify the source code of that plugin so it could fits in my design scheme. Now I don't know if it is a good idea.
I didn't find a way to make a "child plugin" so at this moment I don't know if continue editing the source of this plugin, (that means that I would never update my plugin because I would lose all the modifications) or simply make everything by my own that would take me a lot more of time.
Do you have some suggestion?
You should take a look into world of hooks and filters.
This is nice place to learn from. Here is list of WP hooks where you can hook your code.
And Woocommerce hook example how to cusom validate field.
First part: woocommerce_checkout_process is place where to hook code and my_custom_checkout_field_process is name of your function.
/**
* Process the checkout
*/
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
function my_custom_checkout_field_process() {
// Check if set, if its not set add an error.
if ( ! $_POST['my_field_name'] )
wc_add_notice( __( 'Please enter something into this new shiny field.' ), 'error' );
}
Some plugins have template files, that you can put into child theme.
But sadly not all plugins are well customizable.
I am coding some permalinks rewrite for WooCommerce awesome plugin.
Everything is well packed in a plugin and work well... except for one thing.
WooCommerce use get_term_link() to display HTML link in default template. A lot of custom templates use it too. If I want to display the good link on my website, I must change one line of code in woocommerce plugin. This is dirty, since basic user would not do it. Since I want to list it on Wordpress plugin repertory, I would like some help here...
What I need to do :
Open woocommerce.php and replace line 767 :
OLD
$product_category_slug = empty( $permalinks['category_base'] ) ? _x( 'product-category', 'slug', 'woocommerce' ) : $permalinks['category_base'];
NEW
$product_category_slug = '';
Very easy to do by editing the file, but it is dirty. It is non user friendly, and it depends a lot of woocommerce next version... So my question here: how can I do it from my own plugin, without asking people to open their woocommerce plugin with Notepad++... Is there any way ?
I hope you understand my need and could provide me with an answer :)
I already did same thing in Past.
Please Don't Modify WooCommerce Core files, Because it will be gone in your next upgrade.
Use this Custom Permlink Plugin, You will get Better Options there,
Yesterday I installed a new theme on Wordpress on my self-hosted website. I am aware of the feature that allows you to preview a theme and have used it to select a new Theme that I want to install.
Problem
I do not want to interrupt normal operations of my website, but this new theme requires a lot of customization before it is ready to go. How do I do this?
My Crappy Solution
Is the only way to go about it to run a virtual server on my desktop? This seems tedious, not to mention all the errors I usually get when switching to the "real" server when doing this.
A better way?
I've been searching on SO as well as the WordPress Forum for an answer as to how to do this, but have come up short. I would have thought this is a common question. Maybe I'm using the wrong search terms [themes, customization, before installing]???
Any help is greatly appreciated! Thanks!
Ok, since your question is a pretty good one and probably not a few people are going through the same process when they decide to update their site, I decided to give a try to the get_stylesheet and get_template filter hooks. It turns out that with a very small plugin, you can easily enforce a specific theme(well in this case any logged-in visitor, but you can change this to use any logic you want) according to a specific rule/s.
Here's the code that you need to put in a file in your plugins directory:
<?php
/*
Plugin Name: Switch Theme
Description: Switches the theme for logged-in visitors, while keeping the current theme for everyone else. !!!NOTE!!! Please back-up your database prior using this plugin - I can't guarantee that it will work with any theme, nor that it won't break your site's set-up - USE AT YOUR OWN RISK(I did a quick test and it seemed to be fine, but haven't done extensive testing).
You don't need to switch to the desired theme before that - you want to keep active the theme that you will display to your visitors - the one that you will see will be used programatically.
Before activating the plugin, change the line that says `private $admin_theme = '';` to `private $admin_theme = 'theme-directory-name';` where "theme-directory-name" is obviously the name of the directory in which the desired theme resides in.
*/
class MyThemeSwitcher {
private $admin_theme = '';
function MyThemeSwitcher() {
add_filter( 'stylesheet', array( &$this, 'get_stylesheet' ) );
add_filter( 'template', array( &$this, 'get_template' ) );
}
function get_stylesheet($stylesheet = '') {
if ( is_user_logged_in() && $this->admin_theme ) {
return $this->admin_theme;
}
return $stylesheet;
}
function get_template( $template ) {
if ( is_user_logged_in() && $this->admin_theme ) {
return $this->admin_theme;
}
return $template;
}
}
$theme_switcher = new MyThemeSwitcher();
So - first of all BACKUP YOUR DATABASE! I tested locally with Twenty Eleven being the default theme and a basic framework theme as my custom theme - the theme options and navigation menus were saved properly.
Then all you need to do is to update the file(change the line that says private $admin_theme = ''; to private $admin_theme = 'theme-slug'; where theme-slug is the name of the directory in which the theme you want to use is).
Also - you won't be able to change the Front page and Posts page options, without this affecting the live site, nor will you be able to change the any shared components that both themes use(Site name, Front Page, Posts page, Posts Per Page, etc options, content and so on).
So if you have no clue whether this solution is for you - well, it depends.
If both themes are not relatively complex, then most-likely you should be able to use this hack. If they are though maybe you should do a second installation of your website as others suggested - I think that a second installation in either a sub-domain or a sub-directory would be the best option for you(simply because moving a multisite database is more complex than moving a normal WP database).
I'd setup local apache server with a wordpress installed to customize and test a new theme. When you finished customizing it then you can upload the theme to your live site and activate it. If there are settings that you need to set in the dashboard then you probably will have to adjust them again. That's one way to test/customize a theme before putting it live.
You could create a network (make WordPress multisite with define('WP_ALLOW_MULTISITE', true);, see : http://codex.wordpress.org/Create_A_Network) and then create one sub-site, then turn it "off" with a Maintenance plugin so it is not accessible to users not logged in as admin, export your posts & data from main blog, import them in sub-blog with WordPress default importer, then apply your new theme to this sub-blog and work on it. When everything satisfies you, apply the theme to the main site and deactivate subsite.