Support » Fixing WordPress » Get_the_excerpt

  • Hello everyone,

    I need help with the get_the_excerpt function… However I don’t really understand how it fits with my theme, and its custom code.

    I dont have a link as I’m working locally, sorry but here is the code that inserts a custom length excerpt on the nivo-slider in my theme.

    function excerpt($num) {
      $limit = $num+1;
      $excerpt = explode(' ', get_the_excerpt(), $limit);
      $excerpt = implode(" ",$excerpt)."...";
      echo $excerpt;

    This ordinarily would work fine, as it grabs the first 30 words of the post in question and then puts ‘…’ after them and a button that says read more.

    However, my client wants just the name of the item to show (in this case they are cupcakes) such as:

    Vintage Cupcakes
    Christening cupcakes


    If I change:

    $excerpt = explode(' ', get_the_excerpt(), $limit );


    $excerpt = explode(' ', get_the_excerpt(), $limit -28);

    I can get just the two words to show… Great…

    But what about when the cupcake name is:

    Baby Shower Cupcakes – 3 words… -28 no longer works.

    Can someone help me rewrite this code to include the first LINE of the post? or is that not possible? or am I barking up the wrong tree entirely??

    I am fairly new to all this, just getting to the right php code took me an entire day, lol so please go gentle. 🙂

    Luckily the ‘client’ is a friend 🙂

    Thanks in advance all.

  • The topic ‘Get_the_excerpt’ is closed to new replies.