hlashbrooke / WordPress-Plugin-Template

A robust code template for creating a standards-compliant WordPress plugin.
https://hughlashbrooke.com/
GNU General Public License v2.0
1.03k stars 329 forks source link

Rewriting the CPT Permalink Slug? #29

Closed tnog closed 7 years ago

tnog commented 9 years ago

Thank you for this plugin template!

I have a question regarding rewrites for the CPT permalink slug. Based on the instructions in your README, I'm adding my arguments to customize my CPT below:

add_filter( 'isi_guide_register_args', 'inquirys_custom_post_filter', 10, 2 );

// Customize post type with {$post_type}_register_args filter
function inquirys_custom_post_filter( $args = array(), $post_type = '' ) {

    // Here are my customizations to the post type
    $args['menu_icon'] = 'dashicons-book-alt';
    $args['labels']['menu_name'] = 'ISI Guide';
    $args['rewrite'] = 'array( \'slug\' => \'implementation-guide-articles\' )';
    return $args;
}

$args['rewrite'] = 'array( \'slug\' => \'implementation-guide-articles\' )';

Yet this function doesn't work. What am I doing incorrectly? Any insights that you could provide would be appreciated.

hlashbrooke commented 9 years ago

It looks like you have slashes in your code there where they shouldn't be - not sure if that's because of the copy/paste into GitHub, but if those are in your actual code then you'll need to remove those. So the rewrite line should look like this:

$args['rewrite'] = 'array( 'slug' => 'implementation-guide-articles' )';