Is there a way to remove the default 'uncategorized' category (from categories in Wordpress admin) upon activating my theme?
This will have to go in functions.php obviously.
As long as you have at least one other category to set as the default, you should be able to go to Settings>>Writing and change the default post category to one of your other categories. After doing this you should be able to delete Uncategorized by going to Posts>>Categories and deleting it there.
You can also change the Uncategorized default category by adding this to functions.php:
// Uncategorized ID is always 1
wp_update_term(1, 'category', array(
'name' => 'hello',
'slug' => 'hello',
'description' => 'hi'
));
as shown in this post: https://wordpress.stackexchange.com/questions/83415/remove-rename-uncategorized-category-in-wordpress
More info on wp_update_term
You can use the wp_delete_category function
<?php wp_delete_category( $cat_ID ) ?>
But you need at least 1 category in WordPress, so as long as you're create extra ones before hand you should be ok.
wp_delete_category reference page:
http://codex.wordpress.org/Function_Reference/wp_delete_category
This Works for me
add_filter( 'woocommerce_product_categories_widget_args', 'remove_uncategorized_category' );
add_filter( 'woocommerce_product_subcategories_args', 'remove_uncategorized_category' );
function remove_uncategorized_category( $args ) {
$uncategorized = get_option( 'default_product_cat' );
$args['exclude'] = $uncategorized;
return $args;
}
Related
I am trying to change the words for various places in Wordpress Admin, for example, change the name of "Dashboard" to something else, but I want it to change across the entire Admin - all the occurances. I tried searching through admin files and replacing words, but this is just too much time consuming.
I don't need the words to be translatable, is there any way to do this? Thanks!
Put this code to the function.php file of your child theme:
add_filter( 'gettext', 'dirty_translate' );
add_filter( 'ngettext', 'dirty_translate' );
function dirty_translate( $translated ) {
$words = array(
// 'word to translate' => 'translation'
'Dashboard' => 'Foo',
'Add new' => 'Bar'
);
$translated = str_ireplace( array_keys($words), $words, $translated );
return $translated;
}
Just replace the translations with your own. You can add as many translations as you need. I'm using this myself - Tested and works.
Thanks for reading, Just had a issue regarding WooCommerce, I want to add a short description checkout page of below billing field.
How to add short description in WooCommerce checkout page of below billing field?
I tried add function, custom code but failed with error.
add_filter( 'woocommerce_get_item_data', 'wc_checkout_description_so_27900033', 10, 2 );
function wc_checkout_description_so_27900033( $other_data, $cart_item )
{
$post_data = get_post( $cart_item['product_id'] );
$other_data[] = array( 'name' => 'description', 'value' => $post_data->post_excerpt );
return $other_data;
}
I was used this code but it is showing inner product info table.
There's no real reason to call get_post(). The $product object is stored in the $cart_item array and the $post object is stored inside the $product. This gets the product's excerpt (aka the short description) to show up in the cart and in the checkout. Now, it isn't likely the make the description show up on the order received page, or in the my account area, or in emails, etc since the only place that the woocommerce_get_item_data filter appears is in the cart class.
One thing to take note of, WooCommerce 2.7 is a major rewrite of WooCommerce and $_product->post->post_excerpt will result in PHP notices about directly accessing product properties. So I've suggested both the 2.6 and 2.7 compatible approaches.
add_filter( 'woocommerce_get_item_data', 'wc_checkout_description_so_27900033', 10, 2 );
function wc_checkout_description_so_27900033( $other_data, $cart_item )
{
$_product = $cart_item['data'];
// Use this for WC2.7
//$other_data[] = array( 'name' => 'description', 'value' => $_product->get_short_description() );
// Use this for WC2.6
$other_data[] = array( 'name' => 'description', 'value' => $_product->post->post_excerpt );
return $other_data;
}
I would like to forbid the contributors from adding categories to posts. What I found out was this function remove_post_type_support(). However in the documentation it doesn't talk about tags or categories. I tried remove_post_type_support( 'post', 'category' ); and remove_post_type_support( 'post', 'categories' ); but neither worked.
Is there a way of doing so?
Try this, it is untested but I think it would work.
Simply deregister the taxonomy from the post type: register_taxonomy is used for both creation and modification.
Put it in your function.php file
if ( current_user_can('contributor') )
function contributors_unregister_categories() {
register_taxonomy( 'category', array() );
}
add_action( 'init', 'contributors_unregister_categories' );
}
I'm having trouble with my search results page in that it is not displaying posts that are a part of a category when searching for the category name. For Instance, If I search for "doors" (which is a cat) all Partners that are in the "doors" category should be displayed in the search results. Right now, only partners that have the word "doors" in their title or content is displayed.
I'm running a searchAll function so the the standard wp search will search everything.
// Define what post types to search
function searchAll( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array( 'post', 'page', 'feed', 'partner','project', 'press', 'review' ));
}
return $query;
}
// The hook needed to search ALL content
add_filter( 'the_search_query', 'searchAll' );
What am I missing?
your query is seraching for post_type, not category_name.
post_type is used for custom post types or taxonomies ..
your query should contain $query->set( 'category_name', array( 'post', 'page', 'feed', 'partner','project', 'press', 'review' ));
however, in some cases (and I do not know the reason) that would not work for sub-categories.
in that case, you should use category-slug (slug) insted.
Ive changed my string to this:
<?php
// Define what post types to search
function searchAll( $query ) {
if ( $query->is_search ) {
$query->set( 'category_name', array( 'post', 'page', 'feed', 'partner','project', 'press', 'review' ));
}
return $query;
}
// The hook needed to search ALL content
add_filter( 'pre_get_posts', 'searchAll' );
I do have custom taxonomies though. Basically I'm trying to create a "Search everything" function.
Im looking to add an action for each of the custom post types registered on my WordPress site (when a custom post type is published).
Now I could just manually add one for each of the types I have like:
add_action( 'publish_book', 'function_title_to_call' );
add_action( 'publish_movie', 'function_title_to_call' );
...
But I wanted to ask if there is a way it could be done so its all automated?
I tried the following without luck:
$arguments = array(
'public' => true,
'_builtin' => false
);
$all_post_types = get_post_types( $arguments, 'names', 'and' );
foreach ( $all_post_types as $one_post_type ) {
add_action( 'publish_' . $one_post_type, 'function_title_to_call' );
}
Any suggestions?