Hi
I recently hit a URL structure issue that I believe affects any HivePress site using a non-empty permalink front. I’ve arrived at what seems like a clean fix, but would like to confirm if this is the right fix? If it is, I believe this could help other HivePress users as well who have been facing the same issue.
The Issue
I wanted blog posts to live under /blog/ as /blog/%postname%/. So I set the WordPress permalink structure accordingly in Settings → Permalinks (as shown in the screenshot).
As soon as /blog/ became the permalink front, WordPress applied it to every HivePress URL as well (including categories, attributes, listings, etc.). The URLs turned into:
/blog/listing/{listing-name}//blog/listing-category/{category-name}//blog/vendor/{vendor-name}//blog/vendor-category/{category-name}//blog/{attribute-name}/{attribute}(attribute archives)/blog/tag/{tag-name}
I wanted HivePress URLs to stay at the root (/listing/…, /listing-category/…, etc.) while keeping /blog/ as the front for only the blog posts.
Here’s the code that I came up with. It solves the problem, but I wanted to check if this is the right way and if the code is correct? If yes, it could definitely help others as well -
<?php
defined( 'ABSPATH' ) || exit;
/**
* Strips the permalink front (e.g. /blog/) from every HivePress taxonomy,
* including dynamically-registered attribute taxonomies.
*
* Hooks into WordPress core's register_taxonomy_args filter, which fires
* inside register_taxonomy() itself — so it catches every code path,
* including HivePress's Attribute component runtime registration.
*
* @param array $args Taxonomy registration arguments.
* @param string $taxonomy Taxonomy name.
* @param array $object_type Associated object types.
* @return array
*/
function hev_strip_front_from_hivepress_taxonomy_args( $args, $taxonomy, $object_type ) {
if ( 0 !== strpos( $taxonomy, 'hp_' ) ) {
return $args;
}
if ( array_key_exists( 'rewrite', $args ) && false === $args['rewrite'] ) {
return $args;
}
$rewrite = ( isset( $args['rewrite'] ) && is_array( $args['rewrite'] ) ) ? $args['rewrite'] : array();
$rewrite['with_front'] = false;
$args['rewrite'] = $rewrite;
return $args;
}
add_filter( 'register_taxonomy_args', 'hev_strip_front_from_hivepress_taxonomy_args', 10, 3 );
/**
* Strips the permalink front (e.g. /blog/) from every HivePress post type.
*
* @param array $args Post type registration arguments.
* @param string $post_type Post type name.
* @return array
*/
function hev_strip_front_from_hivepress_post_type_args( $args, $post_type ) {
if ( 0 !== strpos( $post_type, 'hp_' ) ) {
return $args;
}
if ( array_key_exists( 'rewrite', $args ) && false === $args['rewrite'] ) {
return $args;
}
$rewrite = ( isset( $args['rewrite'] ) && is_array( $args['rewrite'] ) ) ? $args['rewrite'] : array();
$rewrite['with_front'] = false;
$args['rewrite'] = $rewrite;
return $args;
}
add_filter( 'register_post_type_args', 'hev_strip_front_from_hivepress_post_type_args', 10, 2 );
If this approach is confirmed correct, I’m happy to help document it for other users… this seems like a common scenario for many HivePress sites that want a blog section at /blog/.
Thanks in advance for any guidance.
