Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use post_format_rewrite_base filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
May 11, 2023
5 minutes read

Access Premium WordPress Plugins

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 Examples

Example 1: Running the Hook

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... 
                         
    } 
    

Example 2: Adding a Hook Callback

The following example is for adding a hook callback.

    // define the post_format_rewrite_base callback 
    function weplugins_filter_post_format_rewrite_base( $type ) { 
        // make filter magic happen here... 
        return $type; 
    }; 

    // add the filter 
    add_filter( 'post_format_rewrite_base', 'weplugins_filter_post_format_rewrite_base', 10, 1 ); 
    

Example 3: Removing a Hook Callback

To remove a hook callback, use the example below.

    // remove the filter 
    remove_filter( 'post_format_rewrite_base', 'weplugins_filter_post_format_rewrite_base', 10, 1 ); 
    

Contact Us

If you need customization, feel free to Contact Us.

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.