Ahmad Awais

NAVIGATE


SHARE


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?#

Creator of CHAI.new — vibe code ai agents · Founder & CEO of Langbase.com — The most powerful serverless AI agents developer platform to build, deploy, and scale AI agents with tools and memory · Check out the State of AI Agents.

Ex VP DevTools & DevRel Eng. Rapid · Google Developers Advisory Board (gDAB) founding member. 🧑‍💻 AI/ML/DevTools Angel InvestorAI/ML Advisory Board San Francisco, DevNetwork

🎩 Award-winning Open Source Engineer & Dev Advocate 🦊 Google Developers Expert Web DevRel 🚀 NASA Mars Ingenuity Helicopter mission code contributor 🏆 8th GitHub Stars Award recipient with 5x GitHub Stars Award (Listed as GitHub's #1 JavaScript trending developer).

🌳 Node.js foundation Community Committee Outreach Lead, Member Linux Foundation, OpenAPI Business Governing Board, and DigitalOcean Navigator. 📟 Teaching thousands of developers Node.js CLI Automation and VSCode.pro course. Over 142 million views, 24 yrs Blogging, 108K developers learning, 200+ FOSS.

✌️ Author of various open-source dev-tools and software libraries utilized by millions of developers worldwide WordPress Core Developer 📣 TEDx Speaker with 100+ international talks.

As quoted by: Satya Nadella · CEO of Microsoft — Awais is an awesome example for developers.
💜 Loves his wife (Maedah) ❯ Read more about Ahmad Awais.

👋… Awais is mostly active on 𝕏 @MrAhmadAwais

📨

Developers Takeaway

Stay ahead in the web dev community with Ahmad's expert insights on open-source, developer relations, dev-tools, and side-hustles. Insider-email-only-content. Don't miss out - subscirbe for a dose of professional advice and a dash of humor. No spam, pinky-promise!

✨ 172,438 Developers Already Subscribed
Comments 0
There are currently no comments.