How to include a query_vars value in document_title_parts?

If your query var tags is registered properly then the following code snippet will definitely work, I’ve tested it. It’s a modified version of your code snippet. Please make sure to add the code to your functions.php file. function prefix_custom_title($title_parts) { global $wp_query; if (isset($wp_query->query_vars[‘tags’])) { $title_parts[‘title’] = $wp_query->query_vars[‘tags’]; } return $title_parts; } add_filter( ‘document_title_parts’, … Read more

Custom permalink question

What you need is to register your own Rewrite Rule. To do it you should use add_rewrite_rule function. function my_custom_external_rewrite_rule() { add_rewrite_rule(‘^post-type-name/([^/]+)/?’, ‘index.php?page_id=<PAGE_ID>&external_page_name=$matches[1]’, ‘top’); } add_action( ‘init’, ‘my_custom_external_rewrite_rule’ ); And you’ll have to register your custom query variable (using query_vars hook): function my_custom_external_query_var( $query_vars ) { $query_vars[] = ‘external_page_name’; return $query_vars; } add_filter( ‘query_vars’, ‘my_custom_external_query_var’ … Read more

Rewrite query var on postname

So, first up, I don’t believe that you need a rewrite tag in this situation, so you can omit that. The issue, I believe, with the remaining code is that your rewrite rule is only capturing 1 match (because there’s only one set of ()), so subpage isn’t receiving a value. Additionally, your rule seems … Read more

Theme customisation – how to store javascript externally when it utilises php variables?

Since it’s a plugin, you should enqueue jQuery first. Inside your add_action(‘wp_head’, function () { before wp_register_script( ‘custom_script’, get_stylesheet_directory_uri() . ‘/custom.js’ ); add : if ( ! wp_script_is( ‘jquery’, ‘enqueued’ )) { //Enqueue jQuery wp_enqueue_script( ‘jquery’ ); } This will check if jQuery is loaded and if not it will load it. Then, in your … Read more

How can I get custom post types to recognize pretty permalink variables?

Building Custom URLs in WordPress discusses how to use Pretty Permalinks to display posts using additional parameters. Jump to the section on Custom Query Vars. That’s where your situation begins to be addressed directly. In particular, you may want to use the example using ‘pre_get_posts‘ to retrieve parameters and adjust the WP_Query using a meta_query, … Read more