Shorten the post title with CSS - by designerobot

This topic has 6 replies, 3 voices, and was last updated 4 years, 11 months ago ago by Rose Tyler

  • Avatar: designerobot
    designerobot
    Participant
    June 4, 2019 at 15:07

    In past you helped me to shorten the portfolio’s post title and not let it go on two lines. You suggested to me to insert this piece of script in content-portfolio.php

    <?php if(etheme_get_option('project_name')): ?>
                        <?php
                            $title = get_the_title();
                            if( strlen( $title ) > 22 ){
                                $title = substr( $title, 0, 22 ) . '...';
                            }
    
                        ?>

    Now my question is, is there a way to move this script from content-portfolio.php to style.css? In order to have something like this:

    @media only screen and (max-width: 1200px){
       /* title is 25 characters */
    }
    
    @media only screen and (max-width: 992px){
       /* title is 20 characters */
    }
    
    @media only screen and (max-width: 768px){
       /* title is 15 characters */
    }

    Thanks

    5 Answers
    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    June 4, 2019 at 15:12

    Hello,

    1) That code is not the script, it’s PHP code.
    2) You can’t use PHP code in the CSS file. CSS file accepts only CSS code.

    Regards

    Avatar: designerobot
    designerobot
    Participant
    June 4, 2019 at 15:16

    Thanks for the quick response. I understood the difference.
    Isn’t there a way to make the PHP code communicate with the CSS code?
    Do you say it’s impossible to get what I asked for earlier?

    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    June 4, 2019 at 15:56

    Hello,

    There is no way to limit word by N characters using CSS.

    Regards

    Avatar: designerobot
    designerobot
    Participant
    June 4, 2019 at 21:08

    I solved, thanks!

    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    June 5, 2019 at 07:04

    Hello,

    You’re welcome!
    Have a nice day.

    Regards

  • Viewing 6 results - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.