The forums are closed and will be removed when we launch our new site.
Looking for support? You can access the support system via your account.
Forums › Forums › Search & Filter Pro › Page Title using first post title
Tagged: page title
- This topic has 8 replies, 3 voices, and was last updated 8 years, 3 months ago by Trisha Miller.
-
Trisha Miller(Private) May 2, 2016 at 8:11 pm #44536
Greetings Ross & Trevor,
Small issue, not critical, but would be nice to correct it if possible. On my search results pages, for the page title it is using the title of the first result – I found instructions for fixing it here:
http://www.designsandcode.com/documentation/search-filter-pro/search-results/as-an-archive/
(at the bottom under “Update Page Title”) However it doesn’t seem to be working.
I have three forms that produce search results, so the only change I made was to change the form ID to an array, but it also didn’t work when I limited it to one form ID and tested that form – this is what I have in my functions file:
add_filter('wp_title','search_form_title'); function search_form_title($title){ global $searchandfilter; if ( $searchandfilter->active_sfid() == array(724,725,727)) { return 'Search Results'; } else { return $title; } }
I’m using WP 4.4.2 – is it possible that this no longer works with 4.4.2? Is there something Iām doing wrong?
Trevor Moderator(Private) May 3, 2016 at 7:46 pm #44628Ross may well come back on this, but I do not think that this function (active_sfid) can take an array. Thus the code may have to be using ORs instead:
add_filter('wp_title','search_form_title'); function search_form_title($title){ global $searchandfilter; if ( $searchandfilter->active_sfid() == 724) || ( $searchandfilter->active_sfid() == 725) || ( $searchandfilter->active_sfid() == 727) { return 'Search Results'; } else { return $title; } }
Maybe?
Trisha Miller(Private) May 3, 2016 at 10:18 pm #44651Hi Trevor,
Thanks for the suggestion – it makes perfect sense – I tried that (but to pass PHP syntax validation I had to surround the statements with another set of parenthesis so it was like this:
if ( ($searchandfilter->active_sfid() == 724) || ( $searchandfilter->active_sfid() == 725) || ( $searchandfilter->active_sfid() == 727) )
However it still didn’t work – the (browser) page title still shows the title of the first search result post….
It’s not a huge deal, but I’m concerned about indexing, the confusion factor, and SEO – if Ross doesn’t have a suggestion when he gets back, I’ll probably just hard-code it to readh “Search Results” for all search results pages (which I *think* I can do using if(is_search) ?)
Trevor Moderator(Private) May 4, 2016 at 9:27 am #44666Hi Trisha
My bad on the coding. It was late š
My guess is that Ross is going to be mega busy this week, but I will leave this in as requiring attention and bring it up with him.
Trisha Miller(Private) May 4, 2016 at 6:03 pm #44719Thanks Trevor, this one is very low on my priority list since I can hard-code the title and I think for now I’ll just do that……the other two problems I have are much higher-priority, with the searching for metadata in related posts being the highest. š
Trevor Moderator(Private) May 4, 2016 at 6:09 pm #44720Hi Trisha
I think if we can video conference this on Skype I will have a better chance of understanding what you are doing.
Do you have skype and a webcam or mic?
Trevor Moderator(Private) May 4, 2016 at 6:09 pm #44721I meant the meta stuff (from the other post).
Ross Moderator(Private) May 7, 2016 at 6:41 pm #44983If you are not bothered about giving different names to different pages you can just do
if ( $searchandfilter->active_sfid() ) { return 'Search Results'; }
This should be applied to any search results page then.
Thanks
Trisha Miller(Private) May 27, 2016 at 10:16 pm #46906Update: Still not able to resolve this, but it’s low on my priority list – just thought you might be interested in where it stands.
I’ve tried a dozen variations of the combination of code snippets from above plus a lot of other stuff I found at the WP Codex and Support forum, without any luck.
I did find some vague information about wp_title being deprected, then undeprectated, currently in some sort of limbo but I’m not sure if it still works in my version of WP which is 4.4.2. I found some information that says theme developers should now be hooking into “wp_get_document_title” and/or “pre_get_document_title” and applying filters to “document_title_parts”…sigh…..so after a lot of reading and following examples I came up with this:
add_filter('pre_get_document_title', 'fix_search_document_title',10); function fix_search_document_title() { $title = apply_filters( 'document_title_parts', $title ); global $searchandfilter; if ( $searchandfilter->active_sfid() ) { $title['title'] = sprintf( __( 'Search Results for “%s”' ), get_search_query() ); } else { return $title; } }
BUT it still doesn’t work….it still uses the post title from the first search result found as the page title.
This should be way low on the priority list for you too, but at some point it’s a puzzle I’d like to solve.
-
AuthorPosts
The topic ‘Page Title using first post title’ is closed to new replies.