You can adjust the template to use in the fly based on the type of page you’re viewing. https://codex.wordpress.org/Plugin_API/Filter_Reference/template_include
add_filter( 'template_include', 'portfolio_page_template', 99 );
function portfolio_page_template( $template ) {
if ( is_page( 'portfolio' ) ) {
$new_template = locate_template( array( 'portfolio-page-template.php' ) );
if ( '' != $new_template ) {
return $new_template ;
}
}
return $template;
}
You could use that in conjunction with https://codex.wordpress.org/Function_Reference/get_queried_object to check out information about the page requested, like the title.
This assumes you didn’t just set your page template on the page itself.
Related Posts:
- How to display page content in a page template?
- Single page theme that uses pages for the content
- Trying to list out child pages with WP_Query
- What are the differences between “Latest Posts” and “Static Page”?
- WP_Query with multiple orderby NOT working with ASC and DESC, what’s wrong?
- How to use custom page for all posts with custom url, call another directory?
- WordPress pagination returns the same posts
- Page template query with WP_Query
- Does WordPress generate an automatic page for post formats?
- Single page theme
- Front End Sorting Questions
- Order by menu structure
- Targeting specific pages in the loop
- WP_Query not retrieving by random order under parent
- WP_Query doesn’t get sticky post at the top, when used in a page template
- Set if condition with wp_nav_menu
- Set order of returned items in the WP_Query() class/function
- Pagination of a WP_Query Loop in a child-page page template
- list pages using page.php and NOT page-{slug}.php
- Search pages that are a child of the current page
- Get pagination working for custom loops within page templates
- How to display summary content from a Page (Not a Post) on another page
- How is WP_Query parsed to determine which template to request?
- Serve specific “template” page at any URL that ends in its slug
- WordPress Pagination changes my template
- add_filter(‘query_vars’) not working in custom template
- Display custom tags on pages that have a specific page parent
- Is there a reason why Pages are not publicly_queryable?
- Why post__not_in is ignored?
- Pass $page_id to new WP_Query
- Exclude parent with child pages from WP_Query
- Pagination on template page for custom query redirecting to index.php
- Create a loop on my pages with new “WP_Query”
- Create a page template for “top rated posts” but show full content and not just a list
- All blog data on a page using custom query gives 404 for page 2 and onward
- WP_Query returns different results from get_posts() [closed]
- inserting content of 1 Post to in another with a template hierarchy
- When listing child pages run out of memory
- WPQuery calling specific posts problem
- How to generate feed for custom template
- Display specific page (that is child) content on parent page
- wp_query on page template not working (Genesis framework)
- Pagination for custom loop on custom page template is not displaying anything
- Get query results with a page title
- How to get current page nearest parent id?
- How to get main menu only with wp_nav_menu
- How to create Page templates for showing Blog posts in different layouts?
- Unable to paginate a custom page query
- How to create single page site in WordPress
- Determine if ID is page or post and query the ID
- How to query for a page, get data, then query for child pages of that page
- Get list of all Grandchild Pages
- Custom query does not find pages
- How to get pages of parent (non-recursive)?
- WP Query and multiple pages
- Page template doesn’t display simple HTML if inserted into other page?
- How to separate two columns from one content on a page template?
- What’s the best way to make a blog page on WordPress?
- INNER JOIN custom tables – SQL Query
- Pagination Shows Up But Won’t Work on Custom Gallery Page
- how to get wp_query posts only first letter of alphabet A?
- display the children of the post using the current page as the main parent
- pages shortcode filtering by category
- How to exclude posts by ID within a category/archive loop
- How to create page that lists tags by initial letter?
- Get a page ancestor from a most viewed list
- Category Archive not working for pages
- Retrieving category pages from subcategory returns empty sets
- Fetching $_POST from Page Template into functions.php
- Using URL variables on a custom WP_Query
- Issue in If else condition [closed]
- Show parent’s child and also child’s, child on a page?
- Pagination is not working on custom query inside a custom home page template
- Passing query variables to a custom page template
- get contents and permalink from a specified page
- Hierarchical List Pages as a table
- When importing a database any page with a wp_query in doesn’t work
- Having trouble using this post category query on multiple pages?
- Get next post when using pagination with WP_Query?
- Adding css tweak based on page template
- How to write short code with if else to get page_id?
- Rewrite URL custom search query
- Paginate_Links page 2 doesn’t work
- How to remove “MY WORDPRESS”” Label
- Why is the value zero going in my custom database table?
- Using WHERE on a WP_Query
- Include one page/post into query which is already returning posts
- Trying to use WP_Query to display a custom post type
- I am officially missing something about transient posts
- function wp() does not use meta_query?
- WordPress WP_Query compare not working?
- Search for pages with permalink
- WP Query / Meta Query [duplicate]
- Register Taxonomy – What is `query_var`?
- Insert images into wordpress post with a query
- Custom Page Template Category loop not functioning correctly
- Don’t repeat posts from children in parent taxonomy query
- Get Post ID as a separate RSS feed item
- Toolbar Hidden in a Virtual Page
- Query Not working as expected