Ahmad Awais



Three intuitive WordPress Excerpts hacks for Theme Developers

Ahmad AwaisAhmad Awais

I don’t really remember since how long I have had been using WordPress excerpts inside themes but I think almost all themes make use of the_excerpt() function. In relation to the excerpts, a theme developer needs certain functions like

Custom read more button#

To add a custom read more button you can add following function to your theme’s function.php

Custom length of excerpts#

Default length of WordPress excerpt is 55 words. You can use following funtion in functions.php to reduce it down to 15 or any custom value.

Dynamic length of excerpts#

What if you need dynamic excerpt length? I mean if you are building a complex WordPress theme, you find yourself in a condition where you need length of excerpts to be different for different pages or for different custom post types. I used to have a very lengthy function for this particular purpose whereas I discoveredΒ wp_trim_words()Β a handy function to trim down the content to as many words as you want to with custom more symbol. Here is how I use it.

What do you use?#

Helping businesses build developer-led adoption for 10+ yrs.
VP of Developer Relations (DevRel, DX Eng., Dev Content Docs) at RapidAPI. I'm Hiring!

πŸ“Ÿ Edutainer at Node.js CLI Automation course (100 videos Β· 22 Projects) & VSCode.pro course. Over 36K devs learning. 🎩 Award-winning Open Source Engineer & Dev Advocate 🦊 Google Developers Expert Web DevRel πŸš€ Mars Ingenuity Helicopter code contributor πŸ† 8th GitHub Stars Award recipient 🌳 Node.js foundation Community Committee Outreach Lead, Member Linux Foundation, OpenAPI Business Governing Board, and DigitalOcean Navigator.

✌️ Author of various open-source dev-tools and software libraries used by millions of developers worldwide ⓦ WordPress Core Developer πŸ“£ TEDx Speaker with 100+ international talks.

πŸ”₯ Satya Nadella Β· CEO of Microsoft, said β€” Awais is an awesome example for developers.
πŸ™Œ Leading developers and publishing technical content for over a decade πŸ’œ Loves his wife (Maedah) ❯ Read more about Ahmad Awais.

πŸ‘‹β€¦ Awais is mostly active on Twitter @MrAhmadAwais


Developers Takeaway

Takeaway my professional opinion on open-source, developer relations, growing your business with family, and everything in between! Delivered to your inbox a couple of times every year. I'm even funny at times. I hate spam β€” pinky-promise!

πŸ‘¨β€πŸ’»πŸ‘©β€πŸ’» 168,174 Developers Already Subscribed
Comments 0
There are currently no comments.