New answers tagged

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' ...


-1

This solution works, added to parent theme functions.php: add_filter( 'register_post_type_args', function( $args, $post_type ) { $args['rewrite']['with_front'] = false; return $args; }, 10, 2 );


0

This is going to sound crazy, but the following worked... I put the content in the following directory: /var/www/myexamplesite.com/public_html (and created log/ as well) Along with the following entry in httpd.conf <VirtualHost *:80> ServerAlias www.myexamplesite.com myexamplesite.com DocumentRoot /var/www/myexamplesite.com/public_html ServerName ...


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() . ...


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(); ...


0

I had the same issue on my website http://loctim.com because I wanted the slug like this %category%/%state%/%city% I had 404 pages in changing functions.php and today it is the gallery which was crazy. So i worked all the night and I have found that I had forgotten this part of code : function add_category_endpoint_tag() { add_rewrite_tag( ...


0

This works for me: function force_relative_url ($url) { return preg_replace ('/^(http)?s?:?\/\/[^\/]*(\/?.*)$/i', '$2', '' . $url); } To use it on a permalink: $relative_permalink = force_relative_url (get_permalink ($post->ID));


0

Slugs are unique. You probably have a tag with slug "water-lab" so wordpress renames your Sub category. Please double check that there is not article, tag etc with the same slug


0

For now I used the sanitize_title filter, and removed all unwanted characters, which forces my users to use only [a-z0-9-] as a valid input for titles. ## Allow only [a-z0-9-] in the slug function my_clear_title($title) { $pattern = '/[^a-z_0-9- ]/i'; $replace_with = ''; return preg_replace($pattern, $replace_with, $title); } ...


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/([^/]*)/([^/]*)$', ...


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; ...


0

If anyone's interested, the solution was quite close, I only had to specify the rewrite rule with &post_type=film : add_rewrite_rule( 'projections_dvd/([^/]+)/?$', 'index.php?name=$matches[1]&post_type=film&is_projections_dvd=1', 'top' ); I also changed the query vars to make it simpler : function wpd_query_var( $query_vars ) { ...


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


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, ...


0

Go to Settings/permalinks and click save. To prevent this from being a problem with plugins, or themes that insatiate CPT's/ Taxonomies there is the function flush_rewrite_rules. here is the link from the codex.


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 ...


0

You cannot have a rewrite slug of '/'. Note that using a slug of '', which you will find floating around, will not work for the latest WordPress versions either. If you want a url like http://domain.com/custom-post, there are no bullet-proof solutions, but the answer to this question will give you some leads: Remove slug from custom post type post URLs


0

Short: You don't need .html ending. .html ending can be easily archive by setting in Options > Permalink or using plugin like Custom Permalink. But that's just personal style. Having html or not is now just different in length of URL. For me, the shorter one is better. It's has no effect on SEO score. In the past, .html ending is some kind to distinguish ...


0

404 Possible Error Cases with Permalinks check your apache config and make sure the directory is right. restart the apache process along with MYSQL/similar. make sure mod_rewrite is enabled Apache mod_rewrite for Ubuntu/Debian: sudo a2enmod rewrite sudo service apache2 restart Similliar to mod_rewrite for Nginx by .htaccess: a simpler way is ...


0

After banging my head for hours, I found this plugin very helpful. https://wordpress.org/plugins/custom-post-type-permalinks/ Below is the screen shot of options it gives.


0

Your question seems to have been already answered by a user here: http://stackoverflow.com/a/18516783/844732 However it sounds like your problem would be solved by using this plugin: Relative URL Relative URL applies wp_make_link_relative function to links to convert them to relative URLs. Yoast also has some background on relative URLs.


-2

add_action( 'restrict_manage_posts', 'wp_restrict_manage_posts' ); function wp_restrict_manage_posts() { global $typenow; $args=array( 'public' => true, '_builtin' => false ); $post_types = get_post_types($args); if ( in_array($typenow, $post_types) ) { $filters = get_object_taxonomies($typenow); foreach ...



Top 50 recent answers are included