Rewrite default post type

Use the field in the admin Settings > Permalinks page to set your permalink structure to /blog/%year%/%monthnum%/%postname%/. To prevent custom post types from inheriting the post permalink structure, set with_front to false in your register_post_type arguments for all custom post types. Version 4.4 also added the register_post_type_args filter to allow modification of post type arguments … Read more

Custom rewrite rules for pages

The pattern WordPress uses to recognize pages is (.+?), which will match anything, but is not greedy, so it allows you to put something at the end. The following code works for me in WordPress 3.0.1: it places the extra pattern at the second-to-last place of the list, because the final pattern is so generic … Read more

Display posts with author in the url with custom post types

You can use the %author% tag in the rewrite property in register_post_type(). However, although the rewrite rules are added (after they’re flushed) – WordPress doesn’t replace the tag with its appropriate value when generating the permalink of your post type. For instance you end up with the permalink www.example.com/%author%/gallery-name The following replaces %author% with the … Read more

Custom slug in front of search URL

None of the above worked for me. Found another solution by overwriting the search rewrite rules using the search_rewrite_rules filter. 1 – Add this to the functions.php of your theme: add_filter( ‘search_rewrite_rules’, function($rules) { $new_rules = []; // New search slug here $new_search_slug = ‘zoeken’; foreach ($rules AS $key => $value){ $new_rules[str_replace(‘search’, $new_search_slug, $key)] = … Read more

Can I call a custom plugin with a direct URL

The Simplest way is to add a Query var to the list of query var that WordPress recognizes and check for that newly added query var on template redirect hook ex: add_filter( ‘query_vars’, ‘se67095_add_query_vars’); /** * Add the ‘my_plugin’ query variable so WordPress * won’t remove it. */ function se67095_add_query_vars($vars){ $vars[] = “my_plugin”; return $vars; … Read more

How to make a category page the blog home page?

Update Eliminating all of the other solutions, there is at least one remaining: template_redirect: function wpse121308_redirect_homepage() { // Check for blog posts index // NOT site front page, // which would be is_front_page() if ( is_home() ) { wp_redirect( get_category_link( $id ) ); exit(); } } add_action( ‘template_redirect’, ‘wpse121308_redirect_homepage’ ); You will need to pass … Read more

I want to create a custom slug in WordPress and output JSON. How do I do this?

You can use pre_get_posts as suggested but simply check the global $wp object for the request url.. like so: add_action( ‘pre_get_posts’, function ($query ){ global $wp; if ( !is_admin() && $query->is_main_query() ) { if ($wp->request == ‘cats’){ header(‘Content-Type: application/json’); $cats = array(‘Hobbes’, ‘Simba’, ‘Grumpy Cat’); echo json_encode($cats); exit; } } }); (PHP 5.3+ in this … Read more

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