Is there a way to have duplicate category slugs?

Short answer: No – it can’t be done. Long answer: Category slugs must be unique, regardless of parent. Although quite a few people like to call this a bug, it’s actually by design. Basically, since categories can be moved around at will, the slugs must be unique. Sure, it’s nested properly now, but if you … Read more

Redirecting specific category posts to subdomain

You can use template_redirect action hook to achieve that: add_action(‘template_redirect’, ‘redirect_category_posts’); function redirect_category_posts() { global $post; if (is_single($post->ID) && in_category(‘category-name’, $post)) { $new_url = “http://category-name.mydomain.com/{$post->post_name}.html”; wp_redirect($new_url, 301); exit; } } Please note that both posts in main domain and in sub-domain must have the same slug or post_name for this code to work.

Category count inside the link

Regular expression jiggery pokery identified: <?php $categories = wp_list_categories(‘title_li=&show_count=1&echo=0’); $categories = preg_replace(‘/<\/a> \(([0-9]+)\)/’, ‘ <span class=”count”>[\\1]</span></a>’, $categories); echo $categories; ?>

Optimal way to redirect home page to category archive?

Eliminating all of the other solutions, there is at least one remaining: template_redirect: function wpse121308_redirect_homepage() { // Check for blog posts index // NOT site front page, // which would be is_front_page() if ( is_home() ) { wp_redirect( get_category_link( $id ) ); exit(); } } add_action( ‘template_redirect’, ‘wpse121308_redirect_homepage’ ); You will need to pass the … Read more

Load categories with ajax

The error says it all, you are sending the request to a invalid host. Change this: var ajaxurl=”http://my-site.co.uk <?php bloginfo(“wpurl”);?>/wp-admin/admin-ajax.php”; To: var ajaxurl = “<?php echo esc_js( admin_url( ‘admin-ajax.php’ ) ) ?>”; Note: from your code and description I’m assuming you are generating the jQuery code within PHP and it is not in a js … Read more

Reflect nested categories in appearance > menus

Seems to be a long-standing issue. This plugin seems to do the trick. I’ve also found an alternative solution (which I’ve posted in the thread). Reproduced below: <?php add_filter( ‘nav_menu_meta_box_object’, ‘disable_pagination_in_menu_meta_box’, 9 ); function disable_pagination_in_menu_meta_box($obj) { $obj->_default_query = array( ‘posts_per_page’ => -1 ); return $obj; } ?> Update: Needs to be added with priority 9 … Read more

Give specific category its own permalink structure

Try these steps: Step #1: Replace this: add_action( ‘init’, ‘custom_rewrite_rules’ ); function custom_rewrite_rules() { add_rewrite_rule( ‘testimonials/([^/]+)(?:/([0-9]+))?/?$’, ‘index.php?category_name=testimonials&name=$matches[1]&page=$matches[2]’, ‘top’ // The rule position; either ‘top’ or ‘bottom’ (default). ); } ..with this one: add_filter( ‘category_link’, ‘custom_category_permalink’, 10, 2 ); function custom_category_permalink( $link, $cat_id ) { $slug = get_term_field( ‘slug’, $cat_id, ‘category’ ); if ( ! is_wp_error( … Read more

Alphabetical Index Page

You can do it like so: // Group the categories by their FIRST LETTER. $groups = []; foreach ( $category_list as &$term ) { $letter = strtoupper( substr( $term->name, 0, 1 ) ); if ( ! isset( $groups[ $letter ] ) ) { $groups[ $letter ] = []; } $groups[ $letter ][] = $term; } … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)