Skip to main content
added 9 characters in body
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

You can do that with a command in your database:

UPDATE `wp_posts` /* Adjust the prefix! */
SET `post_title` = CONCAT(
    UCASE( /* First letter uppercase */
        SUBSTRING(
            `post_title`, 1, 1
        )
    ),
    '',
    LCASE( /* The rest in lowercase */
        SUBSTRING(
            `post_title`, 2, LENGTH(`post_title`)
        )
    )
);

If your author has a habit of posting uppercase titles, you can add a filter per plugin to change titles whenever a new post is added:

add_filter( 'wp_insert_post_data', function( array $data ) {

    // list of words not to change
    $protected_words = [
        'SQL',
        'CSS',
        'BBC'
    ];

    if ( empty( $data['post_title'] ) )
        return $data;

    $words = explode( ' ', $data['post_title'] );

    $words = array_map( function( $word ) use ( $protected_words ) {
        return in_array( $word, $protected_words )
            ? $word
            : mb_strtolower( $word, 'UTF-8' );
    }, $words );

    // There is no mb_ucfirst()
    $words[0] = mb_convert_case( $words[0], MB_CASE_TITLE, "UTF-8");

    $data['post_title'] = join( ' ', $words );

    return $data;
});

You can do that with a command in your database:

UPDATE `wp_posts` /* Adjust the prefix! */
SET `post_title` = CONCAT(
    UCASE( /* First letter uppercase */
        SUBSTRING(
            `post_title`, 1, 1
        )
    ),
    '',
    LCASE( /* The rest in lowercase */
        SUBSTRING(
            `post_title`, 2, LENGTH(`post_title`)
        )
    )
);

If your author has a habit of posting uppercase titles, you can add a filter per plugin to change titles whenever a new post is added:

add_filter( 'wp_insert_post_data', function( array $data ) {

    // list of words not to change
    $protected_words = [
        'SQL',
        'CSS',
        'BBC'
    ];

    if ( empty( $data['post_title'] ) )
        return $data;

    $words = explode( ' ', $data['post_title'] );

    array_map( function( $word ) use ( $protected_words ) {
        return in_array( $word, $protected_words )
            ? $word
            : mb_strtolower( $word, 'UTF-8' );
    }, $words );

    // There is no mb_ucfirst()
    $words[0] = mb_convert_case( $words[0], MB_CASE_TITLE, "UTF-8");

    $data['post_title'] = join( ' ', $words );

    return $data;
});

You can do that with a command in your database:

UPDATE `wp_posts` /* Adjust the prefix! */
SET `post_title` = CONCAT(
    UCASE( /* First letter uppercase */
        SUBSTRING(
            `post_title`, 1, 1
        )
    ),
    '',
    LCASE( /* The rest in lowercase */
        SUBSTRING(
            `post_title`, 2, LENGTH(`post_title`)
        )
    )
);

If your author has a habit of posting uppercase titles, you can add a filter per plugin to change titles whenever a new post is added:

add_filter( 'wp_insert_post_data', function( array $data ) {

    // list of words not to change
    $protected_words = [
        'SQL',
        'CSS',
        'BBC'
    ];

    if ( empty( $data['post_title'] ) )
        return $data;

    $words = explode( ' ', $data['post_title'] );

    $words = array_map( function( $word ) use ( $protected_words ) {
        return in_array( $word, $protected_words )
            ? $word
            : mb_strtolower( $word, 'UTF-8' );
    }, $words );

    // There is no mb_ucfirst()
    $words[0] = mb_convert_case( $words[0], MB_CASE_TITLE, "UTF-8");

    $data['post_title'] = join( ' ', $words );

    return $data;
});
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

You can do that with a command in your database:

UPDATE `wp_posts` /* Adjust the prefix! */
SET `post_title` = CONCAT(
    UCASE( /* First letter uppercase */
        SUBSTRING(
            `post_title`, 1, 1
        )
    ),
    '',
    LCASE( /* The rest in lowercase */
        SUBSTRING(
            `post_title`, 2, LENGTH(`post_title`)
        )
    )
);

If your author has a habit of posting uppercase titles, you can add a filter per plugin to change titles whenever a new post is added:

add_filter( 'wp_insert_post_data', function( array $data ) {

    // list of words not to change
    $protected_words = [
        'SQL',
        'CSS',
        'BBC'
    ];

    if ( empty( $data['post_title'] ) )
        return $data;

    $words = explode( ' ', $data['post_title'] );

    array_map( function( $word ) use ( $protected_words ) {
        return in_array( $word, $protected_words )
            ? $word
            : mb_strtolower( $word, 'UTF-8' );
    }, $words );

    // There is no mb_ucfirst()
    $words[0] = mb_convert_case( $words[0], MB_CASE_TITLE, "UTF-8");

    $data['post_title'] = join( ' ', $words );

    return $data;
});