I stumbled upon an issue that I'm not sure how to go forward with. My theme creates two pages on activation. The fact that there are two doesn't matter, it could be 10 pages but just for the background:

  • One page can be selected as a FrontPage.
  • Another one is used to display all categories.

Both pages use specific page templates, like this:

update_post_meta( $page_id, '_wp_page_template', 'page-all-categories.php' );

Specific styles and scripts and enqueued in my functions.php file like this:

if ( is_page( esc_html__( 'All Categories', 'myslug' ) ) ) {
    // enqueue all categ page styles & scripts

The theme reviewer asked me to have all static strings translated, including these and it makes sense.

However, if the language is switched, with my current approach, these pages will no longer be detected with is_page(esc_html__('MyTheme Front Page', 'myslug') because the title is now in another language.

I assume that re-creating these pages automatically on language switch should solve the issue but I'm not sure what hook I should use, or if I should go in this direction.

1 Answer 1


Page/Post title is the least reliable way to detect specific content as title is easy to edit, but just because it was edited do not mean that functionality should change. Same goes for slugs.

In your specific case, template detection sounds like the best way to go. If there is a somewhat different styling or layout between the pages than give each one a different template.

  • you are right, I don't know how I missed is_page_template() since I was using it in other areas as well. By the way, is creating these pages with the theme activation hook OK by Wordpress princples?
    – Alex C
    Commented Jan 14, 2017 at 19:47
  • you should look at 4.7. try to have a clean install and you will see that there is a new feature in that shows the user a default set of pages he can edit or (I assume) discard. So not only it is in the spirit, and what several themes and plugins do, but you should also check that functionality in core Commented Jan 14, 2017 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.