2

In the site I'm building there is a post-type called "Focus". Since they need to url to be like www.mysite.com/focus/page-post-name I have the post type slug as "focus".

Of course the archive page is www.mysite.com/focus this is causing an issue since I need a specific page to be an archive page. Meta boxes are used to build and add settings to pages. I can't just create a page called "Focus" since that is reserved by the post-type.

My idea is to create a page called "Our Focus" resulting a URL of www.mysite.com/our-focus.

I'd like to just remove the "our-" from that url to make it appear that the archive is being used.

I've tried setting has_archive to false but that just reverts to using the archive.php page.

1

You can add the following to your .htaccess file in between the <IfModule mod_rewrite.c> tags:

RewriteCond %{HTTP_HOST}
RewriteRule ^our-focus/(.*)$ /focus/$1 [R=301,L]

Your .htaccess should looks like the following:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# Custom Rewrite
RewriteCond %{HTTP_HOST}
RewriteRule ^our-focus/(.*)$ /focus/$1 [R=301,L]
</IfModule>
# END WordPress

As a result it will do the following:

http://example.com/our-focus/test

Redirects to:

http://example.com/focus/test
0

If I'm understanding right, you have a post type that uses the /focus slug, but you want a normal page called Our Focus to use that slug instead. You'll need to rewrite the slug for the custom post type in order to use that page, regardless of whether archives are enabled.

If you've made the custom post type in your theme's functions.php file, you can use the 'rewrite' parameter to set another slug. For example:

add_action('init', 'register_cpt');
function register_cpt() {
register_post_type('focus', array(
'label' => 'Focus',
'rewrite' => array('slug' => 'REWRITE-SLUG', 'with_front' => true),
)
) ); }

Replacing 'REWRITE-SLUG' with the slug of your choice.

See this Codex page for more info.

Using a .htaccess rewrite by itself won't work since that slug will still conflict with the custom post type's slug. You'll need to rewrite the slug for the custom post type, and then you can just change the permalink in the page's edit screen to /focus. No need to edit the .htaccess file.

  • I tried using this: 'rewrite' => array('slug' => 'our-focus', 'with_front' => true) so I could use /focus/ as the page's url but it didn't seem to work. I have more than one page I need to do this to. – dcp3450 Jun 30 '14 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.