How do I create a custom permalink structure for a page template

There are different filters available to create the custom permalinks for the posts, custom posts or pages: post_type_link – for custom post types post_link – only for post_types ‘post’ page_link – for pages only ( which you are looking for ) Here is the sample code based on your query: public function custom_permalink_for_page_template( $url, $post … Read more

How to disable permalinks to some custom post content?

When defining a custom post type with register_post_type() an array of arguments is passed. Set the public parameter to ‘false’ to prevent generation of permalinks, as well as other associated actions (search, nav, et al). Using the example from the WP Codex: function codex_custom_init() { $args = array( ‘public’ => false, ‘label’ => ‘Books’ ); … Read more

Loop posts based on permalink term

Got it to work with: $queried_object = get_queried_object () ; and ‘terms’ => $queried_object->slug, full code now: <?php $queried_object = get_queried_object () ; $posts = array ( ‘post_type’ => ‘writing’, ‘posts_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘type’, ‘field’ => ‘slug’, ‘terms’ => $queried_object->slug, ), ), ); $loop = new WP_Query( $posts ); … Read more

Apply function only if end of url has /amp/ [closed]

In your example, $_SERVER[‘REQUEST_URI’] would return /category/post-slug/amp/ which is not the same as get_permalink($post->ID) which would return https://example.com/category/post-slug/ There are lots of ways to go about this, but one easy one that comes to mind is… if ( strpos($_SERVER[‘REQUEST_URI’], ‘/amp/’ ) !== false ) { The strpos() PHP function finds the position of 2nd string … Read more

How to flush Global query variables in wordpress?

The problem is in your rewrite rule: add_action( ‘init’, ‘my_add_rewrite_rules’ ); function my_add_rewrite_rules() { add_rewrite_rule(‘^child/([^/]+)/?’,’index.php?post_type=child&post_parent=$post_id’,’top’); } Instead of using the matched value, you’ve used $post_id. Since this isn’t a double quoted string, and there is no $post_id variable, the value of post_parent will be the string literal “$post_id”, but post_parent expects a numeric post ID … Read more

Redirecting “wrong” but working links to their canonical URL in order to prevent search engine penalties (e.g. /123/ at the end of URLs)

Ensure that you provide a canonical url – this should ensure that search engines don’t see the url variants as duplicate content. Additionally, appending a number on the url, will make WordPress try to access that page. Using a debug plugin, such as Debug Bar, is quite useful for diagnosing this kind of behaviour as … Read more

Relative links in Gutenberg

It doesn’t have anything to do with Gutenberg. It’s just the way WordPress stores links in the main content. Anytime you add a link in the WP editor, it automatically puts in the absolute path. ACF and other forms of custom postmeta instead store the post ID, so whenever its slug/permalink changes they are automatically … Read more

I’ve removed my /author/ slug but it clashes with new and existing pages. Any fixes?

There is no way around uniqueness being necessary, with the effects you described. Personally I wouldn’t remove the part that makes ensuring uniqueness of the slug much easier, like the author part, in my mind it is just a sign of a well structured site. Anyhow, there is validate_username() function with the validate_username hook. You … Read more

custom query var NOT working on a plain permalink: http://10.8.10.9/?page_id=1774/?location=968&floor=1

I think you should really try to make the permalinks work on your server. It seldom fails. Have you checked all your server settings are correct, and have you visited the permalink page after updating, so that the cache is flushed? Otherwise you would have to have http://10.8.10.9/?page_id=1774&location=968&floor=1 and that would work too. I’d really … Read more