Set page template for pages with specific titles
-
Hi,
I want to create a function which will take all pages with a specific name e.g. Events. Then if the template is not set to e.g. ‘my-template.php’ then set it/change it.
Im new to coding and have found that i can get the pages by using:
$page = get_page_by_title( 'Events' );
Im guessing i can set the page template with:
update_post_meta( $page, '_wp_page_template', 'my-template.php' );
Do I need to pull the ID’s for all pages with a certain title somehow? possibly into a foreach page function?
Thanks
Nick
- The topic ‘Set page template for pages with specific titles’ is closed to new replies.