How to add a background image to category and display image on category page

You can try this code. It will add a media button which will get the image url. I have commented the parts that I have deleted or added. function my_category_module() { // this action is deprecated //add_action(‘edit_category_form_fields’, ‘add_image_cat’); // Add these actions for edit and add add_action(‘edited_category’, ‘save_image’); add_action(‘create_category’, ‘save_image’); add_action(‘category_edit_form_fields’, ‘edit_image_cat’); } add_action(‘init’, ‘my_category_module’); … Read more

Moving Categories submenu to Media, but still opens Posts menu

To add to what @brasofilo answered 3 years ago, this is what is necessary in the current menu system (WP v4.5.1). add_action( ‘admin_head-edit-tags.php’, ‘modify_menu_highlight_wpse_43839’ ); function modify_menu_highlight_wpse_43839() { if( ‘post_tag’ == $_GET[‘taxonomy’] ) { ?> <script type=”text/javascript”> jQuery(document).ready( function($) { $(“#menu-posts, #menu-posts a”) .removeClass(‘wp-has-current-submenu’) .removeClass(‘wp-menu-open’) .addClass(‘wp-not-current-submenu’); $(“#menu-media, #menu-media > a”) .addClass(‘wp-has-current-submenu’); }); </script> <?php } … Read more

Get id of category from drop down menu

You’re on the right track with using a form, the only thing you’re missing, you have to submit what you have selected. For example like this: <form method=”GET” action=””> <div> <?php $select = wp_dropdown_categories(‘show_option_none=Select category&orderby=name&echo=0’); $select = preg_replace(“#<select([^>]*)>#”, “<select$1 onchange=”return this.form.submit()”>”, $select); echo $select; ?> <noscript> <div> <input type=”submit” value=”View” /> </div> </noscript> </div> </form> … Read more

How to display parent category name and link for custom breadcrumb

You can use get_ancestors: <?php if ( $term_ids = get_ancestors( get_queried_object_id(), ‘category’, ‘taxonomy’ ) ) { $crumbs = []; foreach ( $term_ids as $term_id ) { $term = get_term( $term_id, ‘category’ ); if ( $term && ! is_wp_error( $term ) ) { $crumbs[] = sprintf( ‘<a href=”https://wordpress.stackexchange.com/questions/225528/%s”>%s</a>’, esc_url( get_term_link( $term ) ), esc_html( $term->name ) … Read more

strip last comma from get_the_category

There are two ways to solve this issue. You need a clean array of category names for both, so let’s start with that: $cat_names = wp_list_pluck( get_the_category(), ‘cat_name’); $cat_names is now an array with just the names: Array ( [0] => aciform [1] => Cat A [2] => Cat B [3] => Cat C [4] … Read more

How to: 301 Redirect /category/ to /customname/

Htaccess is your friend in this case. You can create 301 form your old category base to the new like so: RewriteEngine on RewriteBase / RewriteRule ^old_dir/(.*) http://www.example.com/new_dir/$1 [R=301,L] Change old_dir to category example.com to your domain and new_dir to your custom name. Hope this helps. Ohad.

Hide a certain category name without removing it?

To achieve this we need to use get_the_category here. I am going to use this code in several places, so it is more efficient to create a function function exclude_cats($excludedcats = array()){ $categories = get_the_category(); $separator=”, “; $output=””; foreach($categories as $category) { if ( !in_array($category->cat_ID, $excludedcats) ) { $output .= ‘term_id ).'” title=”‘ . esc_attr( … Read more