WordPress.org

Ready to get started?Download WordPress

Forums

SubHeading
[resolved] length limit? (8 posts)

  1. mpmchugh
    Member
    Posted 1 year ago #

    There seems to be a length limit of 156 characters. Can this be increased?

    Thanks.

    http://wordpress.org/extend/plugins/subheading/

  2. mpmchugh
    Member
    Posted 1 year ago #

    Nevermind. It seems there was something odd about the data when pasted in that truncated it.

  3. edupison
    Member
    Posted 1 year ago #

    Is there any way to stablish a lenght limit by characters?

    Thank you

  4. Steve
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    As of the recently committed version 1.7.1, it is possible to limit the subheading displayed using the new subheading filter.

    For example, the following can be added to your theme functions.php file to limit the subheading to 5 words.

    add_filter( 'subheading', function( $value ) {
        return wp_trim_words( $value, 5 );
    } );

    If you require an exact number of characters, simply change the contents of the filter to manipulate the output to the desired format.

    Hope this helps.

  5. edupison
    Member
    Posted 1 year ago #

    I'm sorry, I don't know almost nothing about PHP. What shoud I do with this code? Just paste it in function.php? I've tried pasting this at the top of the file, but gives me error.

    <?php add_filter( 'subheading', function( $value ) {
        return wp_trim_words( $value, 5 );
    } ); ?>

    Parse error: syntax error, unexpected T_FUNCTION in (...)/functions.php on line 1

    Thanks in advance!

  6. Steve
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    OK, not to worry - let's try and solve this one.

    It could be and issue with PHP versions, the method used in the snippet (anonymous function) will only work in PHP 5.3 of greater.

    First option would be to check which version you are using, and then replace what you have with this alternative.

    function trim_subheading( $value ) {
        return wp_trim_words( $value, 5 );
    }
    add_filter( 'subheading', 'trim_subheading' );

    If this isn't the problem we can move on to something else.

  7. edupison
    Member
    Posted 1 year ago #

    Now it doesn't give an error, but is still not working. My vesion is greater than 5.3.

    Where should I notice the limit? In the subheading box, in the WordPress backend, accepting only five words? Or maybe it should let me write as many words as I want and later, in the frontend, show only the first five words?

    Thanks again!

  8. Steve
    Member
    Plugin Author

    Posted 1 year ago #

    OK, that's sounds good to me.

    Using this filter will not limit the number of characters you can enter into the input on the edit page, it only has an affect on the final output.

    So you could enter "This is my example subheading that is too long.", but using the filter with a 5 word limit will only display "This is my example subheading".

    There are other options you can use with the wp_trim_words function, found in the Codex:

    http://codex.wordpress.org/Function_Reference/wp_trim_words

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.