Load child template based on parent

Instead of putting something on the template, you can keep templates clean and add to functions.php a function that use ‘template_include’ action hook to check parent page template and return same template for children pages. add_action(‘template_include’, ‘auto_child_template’); function auto_child_template( $template=”” ) { if ( ! is_page() ) { return $template; } else { $page = … Read more

WordPress pages with hierarchy

If I read your question correctly you just need to set the ‘about’ page as a parent to ‘contact’ and ‘opening hours’ then the permalink will be how you want it. To do this go edit page of ‘contact’ and in the page attributes box set the parent to ‘about’ page.

Custom page slug without creating a WP page

You’re close, the query var for passing page slug is pagename: add_filter(‘query_vars’, ‘add_account_edit_var’, 0, 1); function add_account_edit_var($vars){ $vars[] = ‘account-edit’; return $vars; } add_action( ‘init’, ‘add_account_edit_rule’ ); function add_account_edit_rule() { add_rewrite_rule( ‘^my-account/([^/]*)/?’, ‘index.php?pagename=my-account&account-edit’, ‘top’ ); } To capture the value in your rule, you need to pass the value in $matches[1]: add_rewrite_rule( ‘^my-account/([^/]*)/?’, ‘index.php?pagename=my-account&account-edit=$matches[1]’, ‘top’ … Read more

meta_key & meta_value not working with get_pages and custom taxonomy

Custom taxonomies are not meta values, but rather their own thing. I don’t think wp_list_pages() or get_pages() can query based on a taxonomy, so I’d recommend using WP_Query instead: <?php $relevant_pages_args = array( ‘post_type’ => ‘page’, ‘posts_per_page’ => -1, ‘post_parent’ => 65, ‘tax_query’ => array( array( ‘taxonomy’ => ‘relevance’, ‘field’ => ‘slug’, ‘terms’ => ‘alumni’ … Read more

Can I make WordPress use a custom template for a child page

You can filter template_include and replace the single-community.php with a single-child-community.php. Example add_filter( ‘template_include’, function( $template ) { if ( ! is_singular() ) return $template; // not single if ( ‘communities’ !== get_post_type() ) return $template; // wrong post type if ( 0 === get_post()->post_parent ) return $template; // not a child return locate_template( ‘single-child-community.php’ … Read more