-
Notifications
You must be signed in to change notification settings - Fork 877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
%%parent_title%% doesn't work on pages with no parent #985
Comments
...Regarding hiding the preceding or following separator - one idea would be to include them in brackets (or similar) with some kind of "if exists" conditional behaviour that only outputs the mentioned shortcodes/text if the condition matches:
Something along those lines. That would also allow me to include other text in the condition too - or in my own case, a hard-coded separator (I use |
Would be nice to have this resolved. As a temporary fix one can change the wpseo-function.php (not recommended) line 363 adding something like: |
@GermanKiwi @difreo The whole replace functionality has been rewritten/refactored now. This issue should be solved now (non-replaced string being replaced with empty and potential duplicate separators being removed). Regarding the extra text: you can always filter the title to do extra things like that yourself. Ref: #1172 |
Thanks @jrfnl - I've installed the master branch file and I can confirm it works fine - the duplicate separator is removed when there is no parent title. The only remaining issue for me here, is that I need to be able to change the separator character. I'm using Genesis, and as you know the Genesis SEO options get hidden when the WordPress SEO plugin is installed - and that includes the Genesis option for changing the separator character! So there is no way for me to redefine what the %%sep%% variable equates to. So until now I've had to manually replace the %%sep%% string in all of my title templates, with a hard-coded separator (in my case I'm using '»'). But obviously that won't work with %%parent_title%% and your new fix here. It will result in duplicate separators for any page that doesn't have a parent title. The proposal shown in the screenshot at #981 would be a perfect solution - ie. creating a new setting on the Titles & Metas page, which lets me choose which separator character I want to use. Will this proposal be implemented any time soon? It would save the day for me! |
@GermanKiwi I've added a 'wpseo_replacements_filter_sep' filter in an open change to the refactor (#1250). I expect that will be merged before the next release. You like ? ;-) That should solve your issue until a decision has been made about #981. |
Thanks @jrfnl - that new filter sounds good. Can I use it already now, or do I have to wait for it to be merged into the release version of the plugin at wordpress.org? This new filter doesn't seem to exist right now in the master branch file you linked to above. I'm also unsure how to actually use it - is there an example function or documentation I can view to see how it works? Hopefully #981 will be added eventually - that will be the best solution! :) |
@GermanKiwi The filter is part of an open pull request, so it's not in the master yet, nor in the version at wordpress.org. Example on how to use it: function kiwis_title_separator( $sep ) {
return '»';
}
add_filter( 'wpseo_replacements_filter_sep', 'kiwis_title_separator' ); |
Oh and if you want something that should already work with the current master version (not the latest official release), try: function kiwis_title_separator( $replacements ) {
if ( isset( $replacements['sep'] ) ) {
$replacements['sep'] = '»';
}
return $replacements;
}
add_filter( 'wpseo_replacements', 'kiwis_title_separator' ); |
Thanks again @jrfnl - however, I can't get that last function (using wpseo_replacements) to work! I've downloaded and installed the latest master.zip file just now (to achieve this, I removed the existing "wordpress-seo" subfolder from my plugins folder, then I renamed the master.zip copy to "wordpress-seo" and uploaded that to the plugins folder). Then I pasted in your function above, verbatim - didn't change anything. (And I'm not a functions noob either ;) - I've got a bunch of other functions in my functions.php file). But the %%sep%% variable is still resolving to a dash character, and not the '»' character that is specified in the function. Do I need to add some particular priority to this function, maybe? Any other ideas? |
My apologies, posted too quickly, it should of course be: function kiwis_title_separator( $replacements ) {
if ( isset( $replacements['%%sep%%'] ) ) {
$replacements['%%sep%%'] = '»';
}
return $replacements;
}
add_filter( 'wpseo_replacements', 'kiwis_title_separator' ); Oh and just make sure that if you use a Unicode character for the separator, that you save the file in the right encoding. |
Okay we're getting there! :) That updated function does the trick - now my separator symbol is » rather than a dash. But this seems to introduce a new problem (or rather, the original problem) - when this function is active, the titles of my pages which do not have a parent page now show a double separator character. In other words, the fix you created to remove the 2nd separator when there is no parent page, doesn't seem to work when this function is active. Example: my Pages title template looks like this: %%title%% %%page%% %%sep%% %%parent_title%% %%sep%% %%sitename%% With your function active, the title of one of my pages - which has no parent - is this: Foobar » » My Site Name Note the double '»'. But when I disable your function, the page title is this: Foobar - My Site Name (ie. the separator is now the default dash character, and it correctly hides the 2nd separator). Good luck! :) |
@GermanKiwi You're completely right. I hadn't taken the filter into account when writing the undoubling code. Fixed this now and committed to master. Thanks for keeping me on my toes ;-) |
Perfect - all working great now! Thanks so much! |
…elpers Add specs for url helpers
I've just added the following to the Pages title template at SEO -> Titles & Metas:
%%title%% %%page%% %%sep%% %%parent_title%% %%sep%% %%sitename%%
It works fine for my pages which do have a parent page, but for my pages that have no parent, their titles look like this:
Kittens » %%parent_title%% » My Site Name
...ie. the %%parent_title%% shortcode stays as-is.
I'd really like to use this shortcode in the Pages title template, so that it automatically applies to all appropriate pages without requiring any further work from me (which is the main advantage of these templates!) - rather than having to manually enter it into the "SEO Title" field of the WP-SEO meta box on each individual page, which would obviously be a nuisance and would somewhat defeat the purpose of having a nice shortcode in the first place.
Could this shortcode therefore be updated, please, so that it hides itself when no parent page exists?
It would also need to be able to hide the preceding (or following?) separator too - otherwise pages with no parent would have two separators right next to each other.
Cheers!
The text was updated successfully, but these errors were encountered: