Forum Replies Created
-
AuthorPosts
-
August 14, 2014 at 7:05 am in reply to: Keeping the 'Private' prefix on filtered page titles #118766GermanKiwiMember
Yeah I saw that one yesterday too. Unfortunately it doesn't quite help because it will not return false anymore once the user has entered in the password. In other words, I could only use it to display a prefix on the title *before* the user entered in the password - after that point, the prefix would no longer be displayed - which is different to the behaviour of WordPress with the regular title.
I have found another solution that seems to work though, for password-protected pages, whether the password has been entered or not:
$post = get_post(); if( !empty( $post->post_password ) ) { >code for adding a prefix to my custom title< }
In fact I believe this is the code used by the original 'private_title_format' filter too. I guess this is the best way to do it, in lieu of ‘get_post_status’ supporting password-protected posts.
Thanks for all your help!
August 13, 2014 at 10:22 am in reply to: Keeping the 'Private' prefix on filtered page titles #118596GermanKiwiMemberOkay, it all makes more sense to me know. I think the best way is to use 'get_post_status' as per your 2nd example above.
The only remaining issue there, is that 'get_post_status' does not return any unique value for password-protected pages - which I find rather odd! It covers every other status type except that. Which means I can't use it to prepend "Protected" to the title for applicable pages. I'll have to search for another solution for those pages I guess.
August 12, 2014 at 7:48 pm in reply to: Keeping the 'Private' prefix on filtered page titles #118482GermanKiwiMemberOkay, I think I understand. I guess what I'm wanting to know, though, is why the title text (from $PageHeading) doesn't get passed through the "private_title_format" and "protected_title_format" filters. Surely that would cause the appropriate prefixes to get added to the title text?
Is it a matter of priority, ie. is my function perhaps firing *after* those two filters have already filtered the original title text? And therefore, when the title text gets replaced with the contents of $PageHeading, the new text won't get passed through those two filters again? (Sorry if my understanding of how this works is incorrect).
August 12, 2014 at 6:09 pm in reply to: Keeping the 'Private' prefix on filtered page titles #118474GermanKiwiMemberThanks - although I'm not sure that is actually correct. The function actually works fine as it originally was, in terms of displaying the correct text in the page title. Which is to say, if I add my own text to my custom meta box (retrieved as $PageHeading), this text is displayed on the page. And if I *don't* add my own text to the meta box, then the default page title is displayed instead. So the function works even without the "else" statement.
I tried your modification anyway, but that hasn't made any difference in terms of the "Private" prefix being added, which implies that it's still not passing through the "private_title_format" filter. Do you have any ideas about that, per my previous question?
BTW I'll leave my function the way you've modified it, because it looks neater even if the previous way worked anyway. 🙂
August 12, 2014 at 4:12 pm in reply to: Keeping the 'Private' prefix on filtered page titles #118465GermanKiwiMemberThanks for that tip!
Okay here's a follow-up question: with my function above, why isn't the $PageHeading variable passed through the "private_title_format" filter after it is returned by my function here? Because if it *was* passed through "private_title_format" then it would surely have the "Private:" prefix added to it, which would solve my problem. Right?
The regular $title variable does get passed through "private_title_format", and my function above is simply changing the contents of $title, so surely that should then get sent through "private_title_format"?
GermanKiwiMemberThanks for the suggestions regarding using that plugin!
However, I'd really rather not use a plugin like that to try and accomplish this. The plugin provides functionality that I don't want or need (eg. recording the URLs of deleted posts and pages etc), and in any case I don't want to install a whole plugin just to provide the functionality of a 410 template - I'm sure it should be possible to achieve what I want using a template file and/or a function in my functions.php file.
Here's the function that I already tried to use (along with a corresponding 410.php file in my Genesis child theme directory):
function error_410( $template ) { if( is_404() && '410' == $_SERVER['REDIRECT_STATUS'] ) { status_header( 410 ); if( file_exists( get_stylesheet_directory_uri() . '/410.php' ) ) { return get_stylesheet_directory_uri() . '/410.php'; } } return $template; } add_filter( 'template_include', 'error_410' );
However, it doesn't work (when tested against a test URL I created using the Redirection plugin which is set to give the 410 status).
From my troubleshooting, I believe the problem is with this bit:
$_SERVER['REDIRECT_STATUS'] )
As far as I can tell, this isn't triggering on my test URL at all. If I use http://web-sniffer.net on this URL, it does show that the HTTP status is 410, so I know that part is working. And I have also been able to confirm that the "if( is_404())" part of the function works fine. So I believe the problem is with the above bit of the function.
Is there an alternative, or better, way to detect the HTTP status code of a given page, using a WordPress function? I think if I could get this bit of the function working, then the rest of it might just work too.
GermanKiwiMemberHi Susan, thanks for replying! No, this issue is still not resolved, so I'd love to hear of any suggestions or a solution that you might have.
The site in question is http://www.ibcstuttgart.de.
As an example to test with: if you add /html to the end of that URL, you'll get a 410 error (in the HTTP header) but the page will be using the Genesis 404 template. (I don't want to provide a clickable hyperlink here to the 410 URL coz it may get indexed by Google from this forum, which I don't want! So just add /html to the end of the domain and you'll get it.)
Thanks!
GermanKiwiMemberThat worked perfectly, thanks! I used the functions.php method as I haven't gotten around to creating custom templates yet. 🙂
Cheers!
-
AuthorPosts