Wordpress - Hide category from sidebar - wordpress

I'm using "Recently Viewed Posts" widget for my website showing what visitor recently visited post/page, by default the widget show all category posts from the list, I need a way to hide a post category from from the widget.
Anyways here's my code.
<?php
function exclude_widget_categories($args){
$exclude = “3,6,18”; // The IDs of the excluding categories
$args[“exclude”] = $exclude;
return $args;
}
add_filter(“widget_categories_args”,”exclude_widget_categories”);
?>
I Took that from here: Wordpress - Exclude a category from appearing in menu or sidebar widgets

Related

ACF field in function.php

Following the request of an SEO agency, I'm trying to recover the content of a field (that I created via ACF in the product categories of WooCommerce) in a function of the functions.php file. I've tried a few tricks found on the net, but nothing works, I can't recover the content.
It's to replace the product category title by another one (the one of the new ACF field) and that this title is only displayed on the category archives of the site (not in the menus and other widgets where the default title is displayed.
Here is the code I did. I get the ID back fine if I display it, I make progress but nothing for $value
<?php
$query_id = get_queried_object_id();
function titre_seo_cat_prod() {
// recupere la valuur d'un post specifique
$value = get_field( 'titre_seo_categorie_de_produit', $query_id );
return $value;
}
?>

Woocommerce Product Page Breadcrumb-title edit

i want it to be
I want to replace the top Store page name on the wordpress product page with the product name, can anyone help?
example:
i want it to be
How can I do? There is no such setting in the properties of the theme?
Not knowing what theme you are using or how the Shop title is being generated, try adding this code to your functions.php file
add_filter( 'woocommerce_page_title', 'woo_shop_page_title');
function woo_shop_page_title( $page_title ) {
if( 'Shop' == $page_title) {
return the_title();
}
}
This code replaces the page title Shop with the title of the product (post).

Hide Sidebar In Woocommerce

In woocommerce shop page (archive-product.php) i have listed category instead of product-listing, which list parent category (Shop page display:Show Category),so when i click in parent category im redirect to child-category (Category display: Show sub Category) listing page,lastly when click on child-category im redirect to product listing of child-category,so im trying hide side-bar in parent-category and child category but display side-bar on product listing.
i found that shop-page uses archive-product.php (parent category displaying page) but both child-category and product listing uses taxonomy-product_cat.php so i couldn't assign different template to for displaying product listing as taxonomy-product_cat.php allow us for using different template (wc_get_template( 'archive-product.php' );)
i try to disable side-bar by following code putting it in **archive-product.php**
$prod_categories = get_terms( 'product_cat', array(
'parent' => 0,
));
if ($prod_categories) {
do_action( 'woocommerce_sidebar' );
}
but doesn't work for child-category
may following image will give clear idea
Parent Category Without Side-bar
Child Catgory Wihtout Side-bar
Product Listing With Side-bar

Show children for subcategory archives in Woocommerce Product Category widget

I'm building a shop with Woocommerce and using WooCommerce Product Category widget. I have set many product categories with subcategories. One of these categories is "Posters" and has several subcategories, like "Star signs", "Travel", "Nature"…
By default Woocommerce only shows the parent categories which is good. If I click a category "posters", I'm redirected to "posters" category archive page and the widget displays all "Posters" children subcategories and it's perfect.
Now, if I click on one of these "Posters" children subcategories, I'm redirected to the respective archive page, but my navigation doesn't show all other "Posters" children subcategories anymore.
The question:
How do I get all parent category and "sibling" subcategories while browsing a subcategory?
Random example of the standard navigation when collapsed:
Phone Cases
Mugs
Pillows
Posters
Shirts
Stickers
Example of navigation when "Posters" has been clicked:
Phone Cases
Mugs
Pillows
Posters
--Star Signs
--Travel
--Nature
--Abstract
--Typography
Shirts
Stickers
When a subcategory is clicked, e.g. "Nature", the navigation returns to look like the first example given, all collapsed. But I want it to stay expanded like in the second example.
Bellow in the screenshot are my settings for Woocommerce Product Category widget:
Any help will be appreciated.
Your settings are correct. The code below is targeting archives category pages only and it will display now all children subcategories in the Woocommerce Product Category widget, for the current subcategory:
add_filter('woocommerce_product_categories_widget_args', 'widget_product_categories_list_args', 10, 1);
function widget_product_categories_list_args( $list_args ) {
global $wp_query;
// Only for category archives pages
if ( is_tax( $list_args['taxonomy'] ) ):
// Get current category
$current_cat = $wp_query->queried_object;
// Get all Included category terms IDs in the widget
$included_ids = explode( ',', $list_args['include'] );
// Get All Childrens Ids from parent term or from current term
if($current_cat->parent != 0 )
$childrens = get_term_children( $current_cat->parent, $list_args['taxonomy'] );
else
$childrens = get_term_children( $current_cat->term_id, $list_args['taxonomy'] );
// Loop through Children term Ids and add them to existing included ones
foreach( $childrens as $child )
$included_ids[] = $child;
// Replace included product category term IDs in the $args array
$list_args['include'] = $included_ids;
endif;
return $list_args;
}
Code goes in function.php file of the active child theme (or active theme).
Tested and works.

Need help to exclude posts from wordpress blog home page

I am trying to exclude posts from my index page. I have the below code in my functions.php to accomplish that:
function my_cat_exclude($query) {
if ($query->is_home) {
//$query->set('cat','-1,-3,-4,-5,-6,-7,-8,-9,-10');
$query->set('cat','11');
}
return $query;
}
add_filter('pre_get_posts','my_cat_exclude');
I have 12 categories in my blog. I would like to show posts from only one category (category id 11). I don't want to show the rest on homepage.
If I use $query->set('cat','-1,-3,-4,-5,-6,-7,-8,-9,-10'); it doesn't show posts which shares the same category with category id 11. For example, if a post is assigned to two categories category id 5 and category 11, then, it doesn't shows that post in my home page. I would like to show all posts belong to category id 11 on my home page.
If I use $query->set('cat','11'); It shows only category with category id 11. however, it removes the other category posts, custom menus from sidebar widget. Also, removes the menu items from top menu.
Please help.
Thanks
I made some changes to your code and this works fine on my dev site.
function my_cat_exclude() {
if ( is_home() ) {
query_posts( 'cat=11' );
}
}
add_filter('pre_get_posts','my_cat_exclude');

Resources