Hot answers tagged

3

What if we pressed the issue and got flush_rewrite_rules put into core page loads? What are the downsides? The only one I see is performance, and that is minimal. The downside is performance. This function is rebuilding an array that is expensive to rebuild – especially on each page load. Just look inside \WP_Rewrite::rewrite_rules(). On the upside, ...


3

I have updated your code so that the fallback image has post permalink. I hope this helps: if ( has_post_thumbnail() ) { echo '<a href="' . get_permalink($post->ID) . '" >'; the_post_thumbnail(); echo '</a>'; } else { echo '<a href="' . get_permalink($post->ID) . '" ><img src="'. get_stylesheet_directory_uri() . ...


2

You could try the newly register_post_type_args filter to adjust it. Here's an untested example: /** * Set 'with_front' to false for the 'experts' post type. */ add_filter( 'register_post_type_args', function( $args, $post_type ) { if( 'teachers' === $post_type && is_array( $args ) ) $args['rewrite']['with_front'] = false; ...


2

I suppose you could filter wp_unique_post_slug and have it return the original slug for posts, but I'm not sure what kind of side-effects this may have: add_filter( 'wp_unique_post_slug', function( $slug, $post_id, $post_status, $post_type, $post_parent, $original_slug ) { if ( $post_type == 'post' ) $slug = $original_slug; return $slug; }, ...


1

I've been running a highly automated WordPress site with more than 8,500 posts for a year now and my permalink structure of choice is /%post_id%/%author%/%postname%/ This means I can recategorize posts without affecting my permalink and never have to worry if I do something behind the scenes the permalink to a post will never become broken (404 error) and ...


1

I did this before 6 months ago. But I don't remember the way. But I bookmarked a few articles which I followed to do it.Just check it. Remove slug from custom post type post URLs Remove The Slugs from Custom Post Type URL Remove Custom Post Type Slug from Permalinks


1

I fixed my problem as follows: // Adds rewrite rules for shop post type function gtp_add_shop_rewrite_rules() { add_rewrite_rule( '^shop/([^/]*)/([^/]*)/([^/]*)$', 'index.php?shop-category=$matches[1]&width=$matches[2]&height=$matches[3]', 'top' ); add_rewrite_rule( '^shop/([^/]*)/([^/]*)$', ...


1

The problem is when you are trying to get the template directory. You are getting it instead of printing bloginfo() prints the output get_bloginfo() retrieves the output So, the nice piece of code should look like this: <?php if ( has_post_thumbnail() ) { echo '<a href="' . get_permalink($post->ID) . '" >'; the_post_thumbnail(); ...


1

Best way to check the option before setting the permalink is as follows: if ( get_option( 'page_for_posts' ) ) { echo '<a href="'.esc_url(get_permalink( get_option( 'page_for_posts' ) )).'">'.esc_html__( 'Blog', 'textdomain' ).'</a>'; } else { echo '<a href="'.esc_url( home_url( '/' ) ).'">'.esc_html__( 'Blog', 'textdomain' ...



Only top voted, non community-wiki answers of a minimum length are eligible