How to get raw unwritten querystring

$_GET refers literally to ?p=1 part of URL. With pretty permalink if it’s empty then there is nothing to access. WordPress processed either case into query variables of WP_Query class. You should use get_query_var() to retrieve things like this, so in this specific case it would probably be get_query_var( ‘p’ ).

Add rel=canonical to only one page

Check if you are on the front page with is_front_page(). The home page (in WordPress the page with the latest posts) can be checked with is_home(). You can add this to the header.php between <head> and </head>: <?php if ( is_front_page() ) echo ‘<link rel=”canonical” href=”‘ . home_url( “https://wordpress.stackexchange.com/” ) . ‘” />’; ?>

Add Custom Values to Permalinks Through Custom Fields and Posts

I fixed this issue by adding a rewrite rule to my functions.php file at the top: function melon_rewrites($rules) { $new_rules = array( ‘parties/([^/]*)/([^/]*)$’ => ‘index.php?melon-parties=$matches[2]’ ); $rules = $new_rules + $rules; return $rules; } add_filter(‘rewrite_rules_array’, ‘melon_rewrites’); I then changed my cpt to allow a query_var: function register_custom_post_types() { $args = array( ‘labels’ => array( ‘name’ … Read more

Rewriting a date hierarchy into a ‘yyyy-mm-dd’ slug

Internal rewrite rules have to point to index.php and set the proper query vars for WordPress to be able to load the requested object: add_rewrite_rule( ‘magazine/(\d{4})/(\d{2})/(\d{2})/?’, ‘index.php?issue=$matches[1]-$matches[2]-$matches[3]’, ‘top’ ); That should get incoming requests to resolve correctly, however, that’s only half the task. If you call the_permalink for your posts, you’ll still get the format … Read more

Custom Post Type View Button in Admin Gives 400 Error

I found a solution here: Custom post types, taxonomies, and permalinks TheDeadMedic’s solution worked like a charm. function filter_post_type_link($link, $post) { if ($post->post_type != ‘project’) return $link; if ($cats = get_the_terms($post->ID, ‘project_categories’)) $link = str_replace(‘%project_categories%’, array_pop($cats)->slug, $link); return $link; } add_filter(‘post_type_link’, ‘filter_post_type_link’, 10, 2); This checks to see what Project Categories are associated with the … Read more

Rewrite rule not passing variable

Try adding ‘source’ as an custom query var, rather than defining it as a rewrite tag. function wpse162627_add_query_vars( $query_vars ){ $query_vars[] = “source”; return $query_vars; } add_filter( ‘query_vars’, ‘wpse162627_add_query_vars’ ); function custom_url_source() { add_rewrite_rule( ‘^source/([^/]*)$’, ‘index.php?source=$matches[1]’, ‘top’ ); } add_action(‘init’, ‘custom_url_source’);