so I am trying to understand the Wordpress custom plugin creation. I have enabled it to activate and show itself with an icon in the menu but I just need to know how to separate the function from the admin dashboard page and what outputs on the theme.
I created a directory for the plugin and two files inside that, one being the functional file and one as included file to separate the code to make it easier to read when creating the config page for the plugin in the dashboard.
<?php
/*
Plugin Name: Feather Slider
*/
add_action( 'admin_menu', 'register_feather_slider' );
function register_feather_slider(){
add_menu_page(
'feather_slider',
'Feather Slider', 'manage_options',
'feather_slider', // URL Slug
'feather_slider', // Menu Label
'dashicons-images-alt2', 50); // Menu icon & Menu Location
}
function feather_slider(){
include('admin_index.php'); // I want this to handle the plugin config in the dashboard
add_shortcode('test', 'feather_slider'); // I want this to out put a file which creates the slider.
}
?>
Related
I am creating a custom theme and I have copied the file content-product.php to my theme folder. There I have made changes to the html structure and css. I can load of list of products and see the changes working via the short code [products].
However elsewhere on the site I want to display another list of products but from a different category. I would use the shortcode [products category="special category"] These products should be displayed using a different template.
My question is: Where can I inspect the shortcode query? and how can I conditionally load a different template depending on which products are being displayed?
In my themes functions.php file I have started to extend the [products] shortcode like this:
function my_wc_shortcode_product_query_args($args, $atts){
if ( isset( $args['category'] ) && $args['category'] == "Daoine Óga") {
var_dump($args);
// Tell Woocommerce to load my custom template instead of the my-theme/woocommerce/content-product.php
}
return $args;
}
But I'm not sure how I can return or get woocommerce to display my custom template at this point.
The woocommerce file that creates the [products] shortcode can be found at plugins/woocommerce/includes/shortcodes/class-wc-shortcode-products.php
Make a folder in plugins folder called custom-product-templates and make a copy of the woocommerce file class-wc-shortcode-products.php to that folder.
Add the plugin comments to the top of that file:
/*
Plugin name: Custom Product Template
Plugin URI: https://anirishwebdesigner.com
Description: Display custom product templates in woocommerce loop
Author: Linda Keating
Author URI: http://anirishwebdesigner.com
Version: 1.0
*/
Navigate to localhost/wp-admin in browser and to the plugins and activate newly created plugin
I can now safely edit that file so that the shortcode behaviour loads the template I want based on certain criteria.
First extend the class so that it accepts a template attribute
In the parse attributes function add
'template' => '',
Then search for wc_get_template_part('content', 'product'); and modify the code here to load different templates in an if..else statement. Something like:
`if($this->attributes['template'] == 'Daoine Óga') {
wc_get_template_part( 'content', 'childrenproduct' );
} else {
wc_get_template_part( 'content', 'product' );
}`
If there are simpler / better solutions please let me know.
I am using a licenced version of the WordPress Grooni Crane theme
https://crane.grooni.com/promo/
https://grooni.com/docs/crane/search/crane_before_primary_menu_area
I want to add content and images to a section ABOVE the Groovy Menu Plugin (comes with the Grooni theme).
So usually I would create te HTML of the images and content and forcefully add it into the header.php file before the menu gets shown, but upon doing this I saw that the PHP now allows for a content section to be added / displayed before the menu will be displayed using crane_before_primary_menu_area .
My question is: How / where in the Grooni Crane theme do I create / edit this section, so that I dont have to force the HTML into the header file, but so that it rather get added dynamicly using the proper functions.
Code in the header.php file looks like this:
do_action( 'crane_before_primary_menu_area' );
do_action( 'crane_primary_menu_area' );
do_action( 'crane_after_primary_menu_area' );
So it shows 'crane_before_primary_menu_area' first, then it shows the menu bar, and then it should show 'crane_after_primary_menu_area'.
My Question is where / how (on the wordpress CMS) do I create / edit a content section for 'crane_before_primary_menu_area' & 'crane_after_primary_menu_area'
This must be done through the child theme.
Together with the Crane theme It was bundled.
Activate it or create your own new one.
https://developer.wordpress.org/themes/advanced-topics/child-themes/
Insert the hook into the functions.php file that will be called in the action 'crane_before_primary_menu_area'
Sample contents of functions.php for child theme
<?php
if ( ! function_exists('custom_func__crane_before_primary_menu_area')) {
add_action( 'crane_before_primary_menu_area', 'custom_func__crane_before_primary_menu_area' );
function custom_func__crane_before_primary_menu_area() {
$html_content = '<div>Content before menu area</div>';
echo $html_content;
}
}
In the above example, we assigned HTML text to the variable
$html_content = '<div> Content before menu area </div>';
And immediately it was shown to the front
echo $html_content;
However inside the function
function custom_func__crane_before_primary_menu_area () {.......}
you can call any other available functions, and display any content you wish.
I am using a simple theme in WordPress, that pulls it's customizers sections from the plugin ThemeHunk Customizer.
I want to hide certain sections in the customizer section, but when using $wp_customize, it isn't working.
This is what I am trying to hide:
$wp_customize->add_section('section_home_ordering', array(
'title' => __('Section Ordering', 'featuredlite'),
'priority' => 3,
));
This is located in the /wp-content/plugins/themehunk-customizer/featuredlite/customizer/customizer.php file.
I have added this to my functions.php file in my child theme directory:
function customize_register_init( $wp_customize ){
$wp_customize->remove_section('section_default_home');
$wp_customize->remove_section('pro_button');
$wp_customize->remove_section('Docs_button');
$wp_customize->remove_section('section_home_ordering'); - THIS IS THE SECTION I would like removed from the /plugin/ file
}
add_action( 'customize_register', 'customize_register_init', 99 );
It doesn't seem to remove though, like it would if you were removing a section from a parent theme.
Is there another method to do this, or is this not possible to remove from a plugin rather than a parent theme?
Thank you in advance.
SOLVED I use the customize_controls_enqueue_scripts hook to input custom CSS within the wordpress customizer, so I can display certain elements as hidden!
In theme your code works fine. Maybe it depends on action hooks order.
Have you tried?
add_action( 'plugins_loaded', 'customize_register_init', 99 );
You can simply go with these documentation as it shows you can disable particular section of Home Page (FrontPage). You can change order of appearance also from the Appearance > Frontpage Section > Section Ordering.
Reference Link: https://themehunk.com/docs/shopline-theme/#frontpage-section
https://themehunk.com/product/shopline-free-shopping-theme/
I have a developed an e-commerce website with WordPress and WooCommerce plugin. Everything has been done but I want to change the complete layout of the checkout page. I tried finding a plugin to do that but failed.
Is there any way by which I can change the layout or the design of the checkout page?
EDITED:
THE WOOCOMMERCE TEMPLATES:
You can copy the "templates" folder (located inside the woocoommerce plugin folder) to your theme (or child theme) folder and rename it "woocommerce".
Then you can chose inside which file you want to edit to feet your needs.
In your case you will find inside a folder named "checkout". All the files inside this "checkout" folder are the different components of the checkout page layout.
Different files responsible for components on checkout page/form
form-checkout.php is the primary file called for checkout page.
form-login.php renders the login form.
form-coupon.php renders the coupon form.
form-billing.php renders the billing form.
form-shipping.php renders the shipping form. (this is displayed when "ship to different address checkbox is checked)
review-order.php renders the order review block.
payment.php renders payment options block.
payment.php has a loop in which for each enabled payment method another file > payment-method.php is called.
cart-errors.php displays cart error.
thankyou.php is called for displaying order received confirmation. ("order-received" endpoint)
ADDING WOOCOMMERCE STYLE SHEET IN CHILD THEME FOR EASY MODIFICATION
Because some times is very difficult to overrides some specific WooCommerce styles.
Step.1 - Disable the general woocommerce.css file.
Add this PHP code to your active theme's functions file (functions.php):
add_filter( 'woocommerce_enqueue_styles', 'wooc_dequeue_styles' );
function wooc_dequeue_styles( $enqueue_styles ) {
unset( $enqueue_styles['woocommerce-general'] );
return $enqueue_styles;
}
Step.2 - Create a new folder inside your active theme's folder named "woocommerce" (if it doesn't exist yet).
Step.3 - Copy the woocommerce.css file into this newly created folder woocommerce in your active theme's folder.
The woocommerce.css file is located in: plugins/woocommerce/assets/css/woocommerce.css.
Step.4 - Enable (enqueue) the general woocommerce.css file in your active theme.
Add this PHP code to your active theme's functions file:
add_action('wp_enqueue_scripts', 'woocommerce_style_sheet');
function woocommerce_style_sheet() {
wp_enqueue_style( 'woocommerce', get_stylesheet_directory_uri() . '/woocommerce/woocommerce.css' );
}
Options:
— You can also enable/disable others woocommerce css files: see this snippet at woo themes
— You can disable ALL Woocommerce style sheets at once:
add_filter( 'woocommerce_enqueue_styles', '__return_false' );
I've followed the codex; http://codex.wordpress.org/Navigation_Menus
However I believe that because we are trying to do the edits on page that isn't using the main sites theme, it's falling apart.
Our standard theme is Grand College, the theme however we are trying to edit is a BlankSlate theme.
I've made the edits in the BlankSlate functions file and inserted:
function register_my_menu() {
register_nav_menu('example-menu',__( 'EXAMPLE Menu' ));
}
add_action( 'init', 'register_my_menu' );
In the header file I've inserted;
<?php wp_nav_menu( array( 'theme_location' => 'example-menu' ) ); ?>
And in the WP-admin dashboard I've built a menu for 'example': I've added Home and Contact to it. However in the 'Manage Location' section I've only got 2 menu options which is what Grand College gives you by default
However when I view the site, I get the 'main' navigation showing rather than just the example menu.
Do my edits to put a new custom menu in, have to be done on the Grand College theme (The sites standard theme, or am I right to be trying to edit the pages theme?
Any help would be great appreciated.
To register a navigation menu i simply used the following code-
register_nav_menu('example-menu',__( 'EXAMPLE Menu' ));