post_format_rewrite_base filter
Filters the post formats rewrite base.
apply_filters( 'post_format_rewrite_base', string $context )
Description
This filter hook called post_format_rewrite_base that allows you to overwrite the base.
In the core code, this hook looks like the following.
$post_format_base = apply_filters( 'post_format_rewrite_base', 'type' );
You’ll notice that the default base is type
, which will give you post format archive URLs like mydomain.com/type/post-format-slug
.
With the filter hook, it’s extremely easy to change this to something new. Suppose you wanted type
to be types
instead. Your plugin code would look like the following.
add_filter( 'post_format_rewrite_base', 'my_post_format_rewrite_base' );
function my_post_format_rewrite_base( $slug ) {
return 'types';
}
Parameters
- $context : (string) Context of the rewrite base. Default ‘type’.
Live Example
To run the hook, copy the example below.
$type = apply_filters( 'post_format_rewrite_base', $type ); if ( !empty( $type ) ) { // everything has led up to this point... }
The following example is for adding a hook callback.
// define the post_format_rewrite_base callback function filter_post_format_rewrite_base( $type ) { // make filter magic happen here... return $type; }; // add the filter add_filter( 'post_format_rewrite_base', 'filter_post_format_rewrite_base', 10, 1 );
To remove a hook callback, use the example below.
// remove the filter remove_filter( 'post_format_rewrite_base', 'filter_post_format_rewrite_base', 10, 1 );