• Resolved marvix2018

    (@marvix2018)


    Hi,

    I need to know to limit the number of words in the widget? I mean the title words.
    or how to override the widget?

    Thanks,

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    it would be best to limit the title length with CSS, to do that you can add the code below in wp-admin / Appearance / Customize / Additional CSS panel

    
    span.adverts-widget-recent-title {
        width: 200px;
        height: 20px;
        overflow: hidden;
    }
    

    Just adjust the 200px and 20px to values which would suite your website best.

    Thread Starter marvix2018

    (@marvix2018)

    Thanks .. but this not solve the issue, it is trimming the last word.

    Plugin Author Greg Winiarski

    (@gwin)

    I am not sure what are you trying to do? Can you paste a link to a page where you are having this problem and let me know which Advert is causing an issue, that would be helpful.

    Thread Starter marvix2018

    (@marvix2018)

    What I mean that I need with CSS will cut the word (hide part of the word) as I set the width of the span. The better way to truncate the title is by counting the number of the words, then set how many words to display.

    Plugin Author Greg Winiarski

    (@gwin)

    So you want to have for example only one line of text in the title in the Recent Ads widget?

    If so then the CSS code above i pasted will do that, the CSS (as far as i know) cannot count the number of words, but it can hide the text which does not fit inside a container.

    If you want trim the title with PHP then you can create your own versiof of the Recent Ads widget, to do that:

    1. copy the wpadverts/includes/class-widget-ads.php to your theme or child-theme folder.

    2. in the new file change the class Adverts_Widget_Ads to something else for example class My_Adverts_Widget_Ads, change the values in __construct() function and modify the title display in widget() function.

    3. finally in your theme functions.php file add the below code

    
    add_action( "init", function() {
      include_once dirname( __FILE__ ) . '/class-widget-ads.php';
      register_widget( "My_Adverts_Widget_Ads" );
    } );
    

    This will register your own custom version of the Recent Ads widget.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to limit words in widget?’ is closed to new replies.