filtering french characters in the_title

View: New views
7 Messages — Rating Filter:   Alert me  

filtering french characters in the_title

by Simon Blackbourn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi

I'm developing a multi-lingual site that uses password-protected posts, and
my client doesn't want the word 'protected' to appear anywhere.

I'm filtering the_title like so:

add_filter( 'the_title', 'no_prot_in_title' );

function no_prot_in_title( $title ) {

    $pattern[0] = '/Protected:/';                    // english
    $pattern[1] = '/Protegido:/';                    // spanish
    $pattern[2] = '/Protégé :/';                     // french
    $replacement[0] = '';
    $replacement[1] = '';
    $replacement[2] = '';

    return preg_replace( $pattern, $replacement, $title );

}

It works perfectly for English and Spanish, but not for French, so I presume
the accented letters are the source of the problem.

I've tried using é instead of the actual letters é and tried
replacing the space with   but it still doesn't work (btw - there is
definitely a space before the colon in the french translation).

Does anyone know how I might get this to work?

Thanks!
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: filtering french characters in the_title

by scribu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Oct 19, 2009 at 3:37 PM, Simon Blackbourn <piemanek@...>wrote:

> Hi
>
> I'm developing a multi-lingual site that uses password-protected posts, and
> my client doesn't want the word 'protected' to appear anywhere.
>
> I'm filtering the_title like so:
>
> add_filter( 'the_title', 'no_prot_in_title' );
>
> function no_prot_in_title( $title ) {
>
>    $pattern[0] = '/Protected:/';                    // english
>    $pattern[1] = '/Protegido:/';                    // spanish
>    $pattern[2] = '/Protégé :/';                     // french
>    $replacement[0] = '';
>    $replacement[1] = '';
>    $replacement[2] = '';
>
>    return preg_replace( $pattern, $replacement, $title );
>
> }
>

Try this:

return str_replace(__('Protected:'), '', $title);

--
http://scribu.net
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: filtering french characters in the_title

by Ozh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> It works perfectly for English and Spanish, but not for French, so I
presume
> the accented letters are the source of the problem.

you'll probably have to replace 'é' instead of 'é' (or maybe even
é or something like this)


_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: filtering french characters in the_title

by Simon Blackbourn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

thanks for the ideas, but unfortunately neither of them work (i was hoping
scribu's would as it would be future-proof if other languages were added).
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: filtering french characters in the_title

by Demetris :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Oct 19, 2009 at 6:41 PM, Simon Blackbourn <piemanek@...> wrote:
> thanks for the ideas, but unfortunately neither of them work (i was hoping
> scribu's would as it would be future-proof if other languages were added).
>
WP 2.8 added a new filter hook: protected_title_format — have you tried that?

Cheers!

Demetris
http://op111.net/
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: filtering french characters in the_title

by Mike Little :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/10/19 Simon Blackbourn <piemanek@...>

> thanks for the ideas, but unfortunately neither of them work (i was hoping
> scribu's would as it would be future-proof if other languages were added).
>


Hi Simon,

You should be using the 'protected_title_format' filter.

This will do what you want, regardless of the language,


add_filter('protected_title_format', 'my_protected_filter');
function my_protected_filter($prefix) {
    //error_log("received $prefix");
    return '%s';
}


Mike
--
Mike Little
http://zed1.com/
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: filtering french characters in the_title

by Simon Blackbourn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> You should be using the 'protected_title_format' filter.
>
> This will do what you want, regardless of the language,
>


that's brilliant, works perfectly thanks
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers