There are custom posts and taxonomy in my theme (Wordpress). I want to change url of them. At the moment I have sth like this:
www.mypage.pl/catalog/
I need rewrite url like this:
www.mypage.pl/parent/catalog/
I put the code:
'rewrite' => array(
'slug' => 'parent/catalog',
'with_front'=> false,
'feed'=> true,
'pages'=> true
),
This works for page www.mypage.pl/parent/catalog/myproduct, but www.mypage.pl/parent/catalog/ isn't.
Most likely, you just need to flush the permalinks to test your new one out.
After executing your custom post code, run flush_rewrite_rules(); to clear your code and implement your new permalink structure. (you only need to do this once, so remove the code after you've executed it)
http://codex.wordpress.org/Function_Reference/flush_rewrite_rules
Related
Having a strange wordpress custom theme issue that I can't crack.
I have a custom post type 'artists' that I am displaying posts for that include a link with the_permalink();
I expect this permalink to take me to the template that I have named single-artists.php -- but instead it takes me to front-page.php every time, even though the link in the browser is the correct permalink that should take me to the single post page.
I have refreshed my permalinks in settings several times, and I have loaded the page and flushed my cache/removed cookies. Still going to front-page.php, no matter what post I click on, even though the permalink does change each time.
Anything else I should be doing? AFAIK the naming convention for single-artists.php is correct as the post type IS artists.
Classic case of me being a beginner, I hadn't noticed that my posts had been hidden from public. Setting public to true (like below) fixed it. If there's any other newbies who run into this hopefully this helps you!
function create_artist_post() {
$args = array(
'labels' => array(
'name' => 'Artists',
'singular_name' => 'Artist'
),
'public' => true,
'show_ui' => true,
'menu-position' => 20
);
register_post_type('artists', $args);
}
add_action('init', 'create_artist_post');
I want to change "service" and "testimonial" url heap in the Wordpress. Because my domain is in Turkish language and my page is in Turkish too, like this: "http://www.sitename.com/service/sirketler-hukuku/". But "service" and "testimonial" words are in English as you know. So it looks like pulled tooth.
At some part of your code the function register_post_type() will get called, one each for testimonial and services.
You need to change the parameters of this function, specifically the 'rewrite' parameter. If you wrote these functions in your own code, changing is easy. If not hopefully the theme or plugin has filters you can change the parameters from.
So something like
register_post_type( /*other parameters*/, 'rewrite' => array( 'slug' => 'turkish for testimonial') );
Read more at https://codex.wordpress.org/Function_Reference/register_post_type
Is it possible / easy to change the permalink format for portfolios?
I want to have a page called projects, and each “portfolio’ item as a project.
Site
So /projects
and each project is under that: /projects/example/
instead of /projects -> /portfolio/example/
It is possible, but I think that the author of the theme that named this custom post type as 'portfolio' can alter it in the code of the theme,, . It can be hacky to change it on your own because you may break things..
You can try to ask the developers of the theme that you bought to help you with that, I belive it is this theme
http://centum.purethe.me/
right?
Hope they can help you with that, and if not, I'm afraid if you do not post some specific code than community can't help you much either,,,
hth, k
You should check the files of the theme and look for the file where the portfolio posttype is added. You could add here the following code to rewrite the slug.
$rewrite = array(
'slug' => 'project',
'with_front' => true,
'pages' => true,
'feeds' => true,
);
Most of the time the file where the posttypes are added are in the 'lib' folder or something like that.
The title might not be completely clear, but I didn't know how to ask this in another way.
I want to build a system in Wordpress where the user can put some projects together where it would be on an url like http://mywordpress.com/projectbuilder/ or something like that.
Normally I would create an page in the admin menu and set it to a certain template and in the content I would put some text like: "Do not delete this page, this content is not shown".
But I think there must be a better way to add a custom page to a certain URL without adding it in the backend as a page with "useless content" since the content would not be changeable from the backend in this case.
I hope this makes sense. How could I go about that?
I think I could achieve this with a custom plugin but I can't seem to find any code how to go about that. I have found a way to add administration pages in the settings menu on the right. But I want to add a page to the website on the front end.
Sorry i didn't got your question properly. but some what say to create Custom post or taxonomy :
Please check below link
Custom Post and Taxonomies
In your functions.php file add this anywhere:
function themeslug_projects() {
$args = array(
'public' => true,
'label' => 'Projects',
'rewrite' => array( 'slug' => 'projects' ),
);
register_post_type( 'projects', $args );
}
add_action( 'init', 'themeslug_projects' );
Do save your permalink settings again after doing this, this will work surely then..
basically you can do this by creating a rewrite rule and then point to a file.
add_action('init', 'add_rewrite_rule');
function add_rewrite_rule(){
// add_rewrite_rule(REGEX url, location, priority (i.e. top is before other rewrite rules)
//basically tell wordress to add a query var if sidebar is added to url. change sidebar to what you want your link to be.
// i set up a custom post type to make this work called custompostype..it does nothing but just to give post_type a value.
add_rewrite_rule('^sidebar?','index.php?is_sidebar_page=1&post_type=customposttype','top');
}
// register a query var
add_action('query_vars','market_set_query_var');
function market_set_query_var($vars) {
array_push($vars, 'is_sidebar_page');
return $vars;
}
// associate a template with your quer_var
add_filter('template_include', 'market_include_template', 1000, 1);
function market_include_template($template){
if(get_query_var('is_sidebar_page')){
$new_template = (theme or plugin path).'/pages/yourpage.php'; // change this path to your file
if(file_exists($new_template))
$template = $new_template;
}
return $template;
}
after adding any rewrite rule, the changes wont take place until you go into settings->permalinks and hit the "save" button.
So after searching google and through SO, I've found that adding
'with_front' => false`
to the rewrite attribute of a new content type, making
'rewrite' => array('slug' => 'Venue','with_front' => false)
should remove the prepended directory (ex. blog/, that defaults to my other pages).
However, it's just causing a redirect loop..
My default prepended permalink is blog/ which is fine normally. However, I have a custom content type event that I don't wish to have blog/ prepend.
What's happening: url.com/blog/event/new-event-12/
What I want: url.com/event/new-event-12/
What's another/the best way to do this?
Thanks!!
Ok, so this works.
I didn't know you had to refresh the permalinks to have the new code take effect.
The easiest way to do this is to just go to the permalink settings page and click save.