Modify the permalink structure for a specific category

A user posted several correction ideas; unfortunately, they were deleted, but I managed to remember some things and apply them to the code. The 404 error no longer appears; now it generates the following: Try deleting cookies. ERR_TOO_MANY_REDIRECTS add_filter(‘post_link’, ‘custom_permalink’, 10, 3); function custom_permalink($permalink, $post, $leavename) { $categories = get_the_category($post->ID); $news_category = array_filter($categories, function ($category) … Read more

why same category base and single post base don’t work?

When you set WordPress up with: The set-up Custom Permalink Structure: /blog/%postname%/ Category base: blog Generated rewrite rules WordPress generates these rewrite rules: blog/([^/]+)(?:/([0-9]+))?/?$ => index.php?name=$matches[1]&page=$matches[2] blog/(.+?)/?$ => index.php?category_name=$matches[1] Rewrite rule position in the rewrite_rules_array Your post rewrite rule (#1) is positioned earlier (therefore higher priority) than the category rewrite rule (#2) in your rewrite_rules_array. … Read more

How to add .html extension only to pages without child pages?

I think you can achieve the desired functionality by selectively adding the .html extension to specific pages using a custom rewrite rule and the page_link filter. // Add a custom rewrite rule to handle pages with .html extension function custom_html_page_rewrite_rule() { add_rewrite_rule( ‘^([^/]+)(\.html)/?$’, ‘index.php?pagename=$matches[1]’, ‘top’ ); } add_action(‘init’, ‘custom_html_page_rewrite_rule’, 10); // Filter page links to … Read more

How to remove parent slugs from child pages permalinks?

To remove parent slugs from child pages’ permalinks in WordPress and avoid the 404 error, you’ll need to modify your code and add some rewrite rules. First, modify your code to remove the parent slug from the child page’s permalink: function my_pages_permalink($link, $post) { if ($post->post_parent) { $parent = get_post($post->post_parent); $link = trailingslashit(home_url($parent->post_name)) . $post->post_name … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)