Need help allowing user to "rewrite" the slug of a custom post with Option Tree without getting an error

201 posts
  • Located in Canada
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Made it to the Authors' Hall of Fame
+5 more
DanyDuchaine says

Hey guys,

So here is my problem, I have a custom post and I want to allow the user to specify the slug of the custom post as well as the taxonomy from the Option Tree dashboard so here is what I did : http://snippi.com/s/l59xl31

Unfortunately, it give me this error :

WARNING: wp-includes/functions.php:928 – Cannot modify header information – headers already sent by (output started at /Users/kailoon/Sites/wp35/wp-content/themes/MissionWP/includes/cpt-causes.php:4)

I’m pretty sure it’s simple but I can’t find how to fix this.

Can someone help?

Thanks!

332 posts
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 1+ items on Envato Market
+3 more
dekciw says

1. uft-8 without BOM

2. no blank lines before <?php

3. remove all unnecessary white space below the code

4. do not use ?> at the end of code

EDIT: Just checked my CPT snippet, it looks EXACTLY the same. :D Even this line:
            'description' => 'Easily lets you create some beautiful portfolios.',
:D
201 posts
  • Located in Canada
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Made it to the Authors' Hall of Fame
+5 more
DanyDuchaine says

1. uft-8 without BOM

2. no blank lines before <?php

3. remove all unnecessary white space below the code

4. do not use ?> at the end of code

EDIT: Just checked my CPT snippet, it looks EXACTLY the same. :D Even this line:
            'description' => 'Easily lets you create some beautiful portfolios.',
:D

OMG where have you find it? Mine come from my friend : OTOTW

:)

332 posts
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 1+ items on Envato Market
+3 more
dekciw says

Actually, don’t think that I’m accusing you of code stealing or something like that – I do not actually care if someone uses my snippets, etc. I’ve just said it as a fun fact :D You can check my cpt-portfolio.php here -> http://snippi.com/s/g9fwjch – and it works OK. So you’d better check for the stuff I’ve mentioned in my previous post.

Btw, I remember typing those descriptions myself. And never bought any OTOTW items :D

63 posts
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
PrimeThemes says

I suggest use apply_filters for dynamic variable like this,

line 29
'rewrite' => array( 'slug' => apply_filters('custom_causes_post', 'causes') ),
line 58
'rewrite' => array( 'slug' =>apply_filters('custom_causes_tax', 'item-type') )
and in your functions.php,
add_filter('custom_causes_post', 'danny_causes_custom_slug');
function danny_causes_custom_slug(){
     global $options;

     $url_rewrite = $options['theme_causes_item_url'];
     $slug = ( !$url_rewrite ) ? 'causes' : $url_rewrite;

     return $slug;
}

add_filter('custom_causes_tax', 'danny_causes_custom_tax_slug');
function danny_causes_custom_tax_slug(){
     global $options;

     $url_rewrite = $options['theme_causes_item_type_url'];
     $slug = ( !$url_rewrite ) ? 'causes' : $url_rewrite;

     return $slug;
}
201 posts
  • Located in Canada
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Made it to the Authors' Hall of Fame
+5 more
DanyDuchaine says

Actually, don’t think that I’m accusing you of code stealing or something like that – I do not actually care if someone uses my snippets, etc. I’ve just said it as a fun fact :D You can check my cpt-portfolio.php here -> http://snippi.com/s/g9fwjch – and it works OK. So you’d better check for the stuff I’ve mentioned in my previous post. Btw, I remember typing those descriptions myself. And never bought any OTOTW items :D

Doesn’t it come from Option Tree v2? :)

@PrimeThemes : Thanks! Will try this :)

741 posts
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Had an item featured on Envato Market
+4 more
Orbital_Themes says

One small suggestion is that you probably shouldn’t flush_rewrite_rules on every page load. This should be done only once when an option for rewrite slug is changed.

2024 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $250,000+ on Envato Market
  • Sells items exclusively on Envato Market
  • Contributed a free file of the month
+8 more
revaxarts says

One small suggestion is that you probably shouldn’t flush_rewrite_rules on every page load. This should be done only once when an option for rewrite slug is changed.

+1 please never call it on every page load :crying:

201 posts
  • Located in Canada
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Made it to the Authors' Hall of Fame
+5 more
DanyDuchaine says

Ok I won’t I won’t :)

by
by
by
by
by
by