I have been trying for a while now to remove the image link from a Woocommerce product. I tried snippets, css and plugins. But nothing seems to work, until I came across Vitaly Gritsienko's answer of Jul 5 2017.
Although the code he suggests (see below) for the functions.php file works, the hand icon is still visible. How can I remove the hand icon?
//Removes links
add_filter( 'woocommerce_product_is_visible','product_invisible');
function product_invisible(){
return false;
}
//Remove single page
add_filter( 'woocommerce_register_post_type_product','hide_product_page',12,1);
function hide_product_page($args){
$args["publicly_queryable"]=false;
$args["public"]=false;
return $args;
}
Actually, the simplest way is to edit the theme's woocommerce listing page to remove the link from the templating engine, although it's better to do it via a child theme so as not to interfere with the main theme's updates.
You can read more about child themes here: https://www.smashingmagazine.com/2016/01/create-customize-wordpress-child-theme/
Related
I'm working on a project that is running of a child theme of TwentySeventeen and whilst the rest of the site doesn't have a sidebar, WooCommerce seems to have it.
For example, the shop page has it - I have tried a few things already and none work without caveats or didn't work at all:
I tried copying archive-product.php to my theme dir in woocommerce/archive-product.php and removing the below:
do_action( 'woocommerce_after_main_content' );
This didn't work.
I then tried doing:
remove_action('woocommerce_sidebar','woocommerce_get_sidebar',10);
...this didn't work either.
I found this answer and it worked, but didn't make the page full width (still had space for the sidebar) and a comment on the answer noted using that method isn't a great idea.
I also found this answer but it involves adding CSS, something I'd like to avoid as it isn't the most robust method in-case class names change in the future etc...
Isn't there a proper way of doing this without potential side affects?
Please, add this code to your functions.php
For remove only woocommerce side bar
function disable_woo_commerce_sidebar_mms() {
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
}
add_action('init', 'disable_woo_commerce_sidebar_mms')
for remove all side bars
function remove_sidebar_mms() {
return false;
}
add_filter( 'is_active_sidebar', 'remove_sidebar_mms', 10, 2 );
OR
You can try this with to increase the priority hope fully its work
remove_action('woocommerce_sidebar','woocommerce_get_sidebar',25);
With the help of Mannu saraswat's answer and some fiddling around I came up with a solution:
// Remove the sidebar
add_action('get_header', 'blm_wc_remove_sidebar_check', 10);
// Removes the sidebar
function blm_wc_remove_sidebar($index) {
return false;
}
// Check to see if we're on a WooCommerce page and if so, remove the sidebar
function blm_wc_remove_sidebar_check() {
if ( is_woocommerce() ) {
add_filter('is_active_sidebar', 'blm_wc_remove_sidebar', 10, 1);
}
}
This avoids having to do the is_active_sidebar check / filter addition on non-WooCommerce pages.
Maybe there is a cleaner way to do this, but this worked for me.
WordPress Divi Theme shortcode adding problem
My Divi version is 3.20.1. I am trying to add my own custom shortcode in the website. However, when I add this shortcode, the elements displayed using this shortcode appear both in the "Edit page" area top section besides the main page.
add_shortcode( "Btx_Show_Testimonial_Main_Page", 'lantry_btx_fun_Main_Page_Show_Testimonial');
function lantry_btx_fun_Main_Page_Show_Testimonial(){
include_once LANTRY_BITECHX_SHORTCODE_DIR_PATH."views/Main_Page_testimonial_show.php";
}
My question is, how can I remove this from the "Edit page" section ??
I provided some screenshot.
Divi module Image Option Select
Show top of the post page
When I remove Divi this problem will be solved. But I need to use Divi.
You can check if a adminuser is logged in and if not execute your function hope this helps but now you have to always log out or use incognito mode to see if its there:
add_shortcode( "Btx_Show_Testimonial_Main_Page", 'lantry_btx_fun_Main_Page_Show_Testimonial');
function lantry_btx_fun_Main_Page_Show_Testimonial(){
if (current_user_can( 'update_core' )) {
return;
}
include_once LANTRY_BITECHX_SHORTCODE_DIR_PATH."views/Main_Page_testimonial_show.php";
}
I don't think the problem comes from DIVI but from your shortcode. Please attach the content of your file Main_Page_testimonial_show.php
The shortcode callback shouldn't produce an output but should return the result.
You can find this on documentation website here. Please pay attention to
Note that the function called by the shortcode should never produce an
output of any kind. Shortcode functions should return the text that is
to be used to replace the shortcode. Producing the output directly
will lead to unexpected results. This is similar to the way filter
functions should behave, in that they should not produce expected side
effects from the call since you cannot control when and where they are
called from.
Here, simply you can create the shortcode in the functions.php file and on your Page/Posts you can use the Text Module and add the [shortcode].
I have this in my index.php file. It adds the home banner image in WordPress. I know that it is mostly generated in WordPress customizer, but I need to add an anchor tag in this section. I can't find it anywhere in the file structure.
<?php do_action('cleanblog_index_top'); ?>
I'm not able to find where cleanblog_index_top leads to. Any help would be great. Thank you!
I stumbled on this old one while looking up the docs for do_action(). The answers are brutal so I decided to provide a better answer in case anyone else stumbles here.
If a WordPress theme has something like do_action( 'example_action_hook_tag' ) somewhere in one of the template files (such as index.php, page.php or whatever) the purpose is to provide theme or plugin authors with a way to write their own custom function that they can then "hook" onto the action with the function add_action().
WordPress would then call this function any time and anywhere do_action( 'example_action_hook_tag' ) is called.
The creators of commercial themes will often litter their template files with hooks declared with do_action() to make it easier for their customers to customize their themes via functions.php or by writing a site-specific plugin.
It looks to me that this is the likely scenario that is impacting the OP. This also explains why the OP was unsuccessful in finding where this "leads to".
It would only "lead somewhere" if the OP wrote a function in the theme/child-theme functions.php or in a plugin and added the line do_action( 'cleanblog_index_top', 'name_of_ops_function' ) to hook their function onto the cleanblog_index_top. WordPress would then call their function when do_action( 'cleanblog_index_top' ) was called in index.php.
From the name of the OP's hook, cleanblog_index_top, it sounds like the theme author intended to provide a way for others to inject output at the top of the index page template.
Suppose the OP wanted <h1>Hello World</h1> to appear there.
In functions.php of a theme/child-theme the OP could add a function that echo's this out:
function op_customization() {
echo '<h1>Hello World</h1>';
}
And hook their function onto cleanblog_index_top:
add_action( 'cleanblog_index_top', 'op_customization' );
Cheers!
You should never edit the index.php file directly, for the same reason you should never edit core Wordpress files directly - the next time WP pushes an update, your changes will be overwritten (and that assumes you don't break anything). Never edit plugin files directly, same reason.
You need to look in your theme, you should only make changes to the functions.php and style.css files in your theme - unless you create a child theme and that is a topic you should Google.
So I have attached an image of my issue.
Basically I followed the instructions on this Stack Overflow question thread right here:
Text under Add to cart (woocommerce)
I posted my question there 5 times and someone kept removing it, so I'm posting it again here. Please advise.
Update: I have already tried the paragraph tag, the break tag, and the pre tag.
You could try this (as you will see this is a CSS styling issue with the margin-top):
add_action( 'woocommerce_after_add_to_cart_button', 'custom_content_after_addtocart_button', 100 );
function custom_content_after_addtocart_button() {
// custom content.
echo '<br/><div><p style="font-size:10px; font-style=italic; margin-top:20px;">(*Contact us for bulk purchase enquiry)</p></div>';
}
Code goes in function.php file of your active child theme (active theme or in any plugin file).
Tested and works. You will get that:
This code will place it nicely below the Add to Cart button :
add_action( 'woocommerce_after_add_to_cart_form','content_after_addtocart', 100 );
function content_after_addtocart() {
// place your content below.
echo 'Hello There !!';
}
i've written a plugin which shortcodes can easily be used in every post and page. As this plugin can be useful in a sidebar as well i want to make the text widget usable for my shortcodes.
When i googled this i found out that i can use the add_filter() function to ensure that, but this is only possible if i have access to the theme's functions.php. But as i am the creator of the plugin and not of the theme, this is not usable for me.
Does anybody know how i can make a shortcode which is introduced with a plugin usable in the widgets section?
Thanks!
Open your theme's function file.
Find a free spot after the opening php tag that isn't part of a function.
add this:
if (!is_admin())
{
add_filter('widget_text', 'do_shortcode', 11);
}
save the file and you should be all set.
Open your page in edit mode.
Select your page location and line where you want to add short code.
Add code here and update..