Child page in custom post throws 404 page not found

It turns out the WordPress permalink structure works perfectly well for custom types, e.g. example.com/recipes/lunch/sandwich/. This works exactly as expected if you set ‘hierarchical’ => true. What I was originally trying to do was unnecessarily difficult to execute, and requires properly setting up a custom permalink structure to avoid 404 errors. I advise you stick … Read more

Custom post type routing with hierarchy

When you declare the custom post type, there is a parameter “rewrite” where you declare the slug for the post type. Change the slug to “media/videos”, and then visit your Settings > Permalinks page to update your rewrite rules. register_post_type( ‘videos’, array(‘labels’ => array(), ‘rewrite’ => array( ‘slug’ => ‘media/videos’, ‘with_front’ => false ) ) … Read more

.htaccess for wordpress in separate folder

Rather than change .htaccess, move the index.php up to root, open it, and change: require( dirname( __FILE__ ) . ‘/wp-blog-header.php’ ); to: require( dirname( __FILE__ ) . ‘/wp/wp-blog-header.php’ ); In Settings, your WordPress address should be http://example.com/wp, and Site address should be http://example.com. This process is outlined in the Codex page Giving WordPress Its Own … Read more

Custom routing for plugins

The WordPress Way of doing it is using query_vars so first you add you vars to the array: //add to query vars function add_query_vars($vars) { $new_vars = array(‘custom_method’,’cm_parameter’); $vars = $new_vars + $vars; return $vars; } add_filter(‘query_vars’, ‘add_query_vars’); then you can check in your plugin for the vars: global $wp; if (array_key_exists(‘custom_method’, $wp->query_vars) && isset($wp->query_vars[‘custom_method’])){ … Read more

Custom URL routing based on cookie value

SESSION variables aren’t reliable, and won’t work on some WP hosts. Even worse, you’re going to prevent caching But more importantly, don’t route, redirect! Routing and redirecting are not the same thing So, we want the following logic: on the template_redirect action if the user is on the homepage aka is_home call wp_safe_redirect redirect to … Read more