Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Help Me] Topic Title Maximum Length and Inspect Element Tool


  • netpro8x
    Participant

    @netpro8x

    Lately a lot of spammers are creating huge topic titles with virtually no limit of chars by just changing the max length size using the browser inspect tool.

    There’s any way to avoid this? The only solution I found was 8 years old 🙁

    Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)

  • Robin W
    Moderator

    @robin-w

    The only solution I found was 8 years old

    may well still be valid – link to this please


    Robin W
    Moderator

    @robin-w

    This code will limit the topic title to 80 or whatever number you set $length to

    Put it in your child theme functions.php file

    add_filter ('bbp_new_topic_pre_title' , 'rew_limit_topic_length' ) ;
    add_filter ('bbp_edit_topic_pre_title' , 'rew_limit_topic_length' ) ;
    
    function rew_limit_topic_length  ($topic_title) {
    	$length = 80 ;
    	if (strlen($topic_title) > $length) {
    		$topic_title = substr($topic_title, 0, $length);
    	}
    return $topic_title ;
    }

    0be1
    Participant

    @obe1968

    Robin;

    I have attempted to add the code you provided to my child themes functions.php file and change the length value to 120. It does not reflect that in either the text on the screen or the actual field length itself. Is there something else I can try?

    Thank you…

    Shawn


    Robin W
    Moderator

    @robin-w

    hmmm…..

    Can you post the copy of the above as you have in your functions file but with any previous function and any subsequent one


    0be1
    Participant

    @obe1968

    Here you go Robin

    function oceanwp_child_enqueue_parent_style() {
    // Dynamically get version number of the parent stylesheet (lets browsers re-cache your stylesheet when you update your theme)
    $theme = wp_get_theme( ‘OceanWP’ );
    $version = $theme->get( ‘Version’ );
    // Load the stylesheet
    wp_enqueue_style( ‘child-style’, get_stylesheet_directory_uri() . ‘/style.css’, array( ‘oceanwp-style’ ), $version );

    }
    add_action( ‘wp_enqueue_scripts’, ‘oceanwp_child_enqueue_parent_style’ );

    add_filter (‘bbp_new_topic_pre_title’ , ‘rew_limit_topic_length’ ) ;
    add_filter (‘bbp_edit_topic_pre_title’ , ‘rew_limit_topic_length’ ) ;

    function rew_limit_topic_length ($topic_title) {
    $length = 120 ;
    if (strlen($topic_title) > $length) {
    $topic_title = substr($topic_title, 0, $length);
    }
    return $topic_title ;
    }

    In my plugin bbp-toolkit I have used a filter on bbp_get_title_max_length.
    Feel free to install the plugin or look at the code on the use of the filter.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar