Skip Navigation

[Résolu] [wpv-post-url] missing .html when permalink set with .html extension

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 5 réponses, has 2 voix.

Last updated by Caridad Il y a 7 années et 11 mois.

Assigned support staff: Caridad.

Auteur
Publications
#194185

Hello,

I've set permalinks to /%postname.html but when I display a posts URL via [wpv-post-url] it just show /%postname/

I thought one solution would be to add a new shortcode adding the ".html" to all links. But then I need to change all [wpv-post-url] shortcodes to this new one, also I have to set the post ID for every link.

How can I use [wpv-post-url] and have the .html shown with my URL's?

#194363

Dear Daniel,

This is working fine over here. Can you try saving permalinks a couple of times? there is no need to make any changes there.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

#194546

I found that custom post types only are affected. Pages do work fine the the .html extension. I checked all plugins that could have effect on it as well as the function.php (where I removed custom post type slug removal). When i enable wp debug there is nothing specific about that. Do you have an idea how to find out what's going on here?

#194781

Dear Daniel,

That is the way WordPress works. See the "rewrite" section here:

http://codex.wordpress.org/Function_Reference/register_post_type

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

#194977

Hi Caridad,

I tried

add_action( 'rewrite_rules_array', 'rewrite_rules' );
function rewrite_rules( $rules ) {
    $new_rules = array();
    foreach ( get_post_types() as $t )
        $new_rules[ $t . '/([^/]+)\.html$' ] = 'index.php?post_type=' . $t . '&name=$matches[1]';
    return $new_rules + $rules;
}

add_filter( 'post_type_link', 'custom_post_permalink' ); // for cpt post_type_link (rather than post_link)
function custom_post_permalink ( $post_link ) {
    global $post;
    $type = get_post_type( $post->ID );
    return home_url( $type . '/' . $post->post_name . '.html' );
}

add_filter( 'redirect_canonical', '__return_false' );
 

http://wordpress.stackexchange.com/questions/59024/add-html-dot-html-extension-to-custom-post-types

It's working now.

#195149

Dear Daniel,

Thanks for getting back to us with a workaround.

Regards,
Caridad