By the time the shortcode handler executes it’s too late to effect the title. You could use the same query var logic as in the shortcode handler to affect the title from the ‘wp_title’ filter callback. I don’t understand why you would have to redo all the queries – you’re just checking them for certain values, not changing them, right?
But what I probably would do is develop an entirely separate custom page template for my photo galleries instead of trying to alter what the default one does.
Hi bcworkz, thanks for your answer!
Let me give you an example of why i’m redoing queries.
if album_id query param is present, we’re dealing with a “Album page” so i have to query for the Album title, number of photos etc.
In the wp_title filter callback i would have to redo at least the query for the album title. Otherwise, all my album pages will have the same page title.
By developing separate custom pages you mean creating different pages for, let’s say, main gallery, album view and photo view? (with different shortcodes or different shortcode args). This will help a bit but still does not solve the “different title for each album” problem.
Ah, I see. You shouldn’t redo the query, you should do a custom secondary query, which I suspect is really the same thing, except you’re failing to call wp_reset_postdata() so that the original query remains valid.
My approach would involve a single page template. The code on that template would be adequate to deal with all the various views, assuming they all have similar structure, only the content is different.(A single template could also handle multiple structures, FWIW) Exactly what it does for each view is determined from the query vars. You don’t really need shortcodes because what the shortcode handler does could be done by the template code. Since you have shortcodes already though, you can make use of them with do_shortcode() or by calling the handler directly.
You would still need to create at least one page based on the template, that may be enough for all conditions. A single page slug is used to access the content, but the title and content the user sees is determined by the query vars. Alternately, additional rewrite rules could obscure that single slug so that even the permalinks relate to the content displayed, the user doesn’t see the actual page slug.
Instead of a page template, this custom template might instead be a supplemental theme template. Depending on the nature of the data, the theme could automatically use such a template, provided it’s named properly. See Template Hierarchy.