Search
 
SCRIPT & CODE EXAMPLE
 

PHP

fix-wordpress-limit-permalink

add_filter( 'sanitize_title', 'wpse52690_limit_length', 1, 3 );

function wpse52690_limit_length( $title, $raw_title, $context ) {
    //  filters
    if( $context != 'save' )
        return $title;

    //  vars
    $desired_length = 20; //number of chars
    $desired_words = 5; //number of words
    $prohibited = array(
        'the'
        ,'in'
        ,'my'
        ,'etc'
        //put any more words you do not want to be in the slug in this array
    );

    //  do the actual work
    // filter out unwanted words
    $_title = explode( ' ', $title );
    //if you want more than one switch to preg_split()
    $_title = array_diff( $_title, $prohibited );
    // count letters and recombine
    $new_title = '';
    for( $i=0, $count=count($_title); $i<$count; $i++ ) {
        //check for number of words
        if( $i > $desired_words )
            break;
        //check for number of letters
        if( mb_strlen( $new_title.' '.$_title[$i] ) > $desired_length )
            break;

        if( $i != 0 )
            $new_title .= ' ';
        $new_title .= $_title[$i];
    }

    return $new_title;
}
Comment

PREVIOUS NEXT
Code Example
Php :: preg match apache log file 
Php :: PHP Number Shortener 
Php :: backend/web/index.php when deploying 
Php :: laravel migration add contraint to other database 
Php :: cant use migrate with sail laravel 
Php :: send email to no register user in laravel 
Php :: contact us page mail prestashop 
Php :: php default argument 
Php :: PHP OOP - Access Modifiers 
Php :: wordpress have same sku 
Php :: magento2 migration 
Php :: Call to undefined function can() laravel spatie 
Php :: 16 digit random password generator php code without function 
Php :: school management system in codeigniter free download 
Php :: php join array to parenthesis 
Php :: virtual fields cakephp 4 
Php :: remove public from laravel 8 url 
Php :: laravel belongsto nested 
Php :: traduction website 
Php :: laravel gigapay get single employee 
Php :: download xampp php 5.3 for windows 7 64 bit 
Php :: getting key from env returns null laravel 
Php :: laravel routes options 
Php :: Parse error: syntax error, unexpected token "implements" in C:xampphtdocsmastervendoryiisoftyii2aseObject.php on line 78 
Php :: If you wanted all questions that had all three of those tags, your query would look like: 
Php :: php ord deprecated 
Php :: accessing class in php 
Php :: codeigniter database metadata 
Php :: afosto/yaac error parsing certificate request 
Php :: correction of controller 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =