Default category link for a custom category is a broken link

I found that the reason flush_rewrite_rules(); wasn’t working was because switch_to_blog doesn’t re-initialize some of the properties of $wp_rewrite (not to mention other parts of WP), so flush_rewrite_rules was still generating some of the rules based on the permalink structure of the current blog (which is not the same), rather than the switched-to blog (84). … Read more

Add .html to Woocommerce permalinks [closed]

This is the simplest way to add .html, which involves overriding the default permastructure: function wpse_178112_permastruct_html( $post_type, $args ) { if ( $post_type === ‘product’ ) add_permastruct( $post_type, “{$args->rewrite[‘slug’]}/%$post_type%.html”, $args->rewrite ); } add_action( ‘registered_post_type’, ‘wpse_178112_permastruct_html’, 10, 2 ); http://codex.wordpress.org/Function_Reference/add_permastruct For categories: function wpse_178112_category_permastruct_html( $taxonomy, $object_type, $args ) { if ( $taxonomy === ‘product_cat’ ) add_permastruct( … Read more

Link won’t show using the_permalink();

because the_title() expects a string for the $before and $after args, you need to use the string version of the permalink, in a string concatenation; <?php the_title(‘<h2 class=”wow”><a href=”‘.get_permalink().'”>’, ‘</a></h2>’); ?> you also had a missing >. https://developer.wordpress.org/reference/functions/get_permalink/

Filter string like a slug

You can use sanitize_title() function: $string = “This is title string”; // return “this-is-title-string” $slug = sanitize_title( $string ); You can also filter the result of sanitize_title() function using sanitize_title filter: add_filter( ‘sanitize_title’ , ‘sanitize_filter_callback’, 10, 3 ); function sanitize_filter_callback( $title, $raw_title, $context ) { // do something }

Customize permalink when creating a post

This can be done using the wp_insert_post_data hook. function house_post_slug( $data ) { if ( $data[‘post_type’] == ‘houses’ ) { $permalink = ”; if ( isset ( $_POST[‘ACF Code Field’] ) ) { $permalink = $_POST[‘ACF Code Field’]; } if ( isset ( $_POST[‘post_title’] ) ) { $permalink .= ‘-‘ . $_POST[‘post_title’]; } $data[‘post_name’] = … Read more