This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
So, you’ve stumbled upon the `category_description` action hook and you’re wondering how to get started? No worries, I’m here to guide you through it! This hook filters the category description for display. Want to know how to use it? Let’s dive in with some live examples.
Live Examples
Example 1: Basic Usage of category_description Hook
In this example, we will add a custom function to the `category_description` hook. This function will be called whenever the category description is displayed.
function weplugins_execute_on_category_description_event($description, $category) { // Add custom functionality here $description .= '<p>Custom text added to category description.</p>'; return $description; } // Add the action add_action('category_description', 'weplugins_execute_on_category_description_event', 10, 2);
Example 2: Conditional Logic in Hook
This example demonstrates how to add conditional logic within your hook function. For instance, you can modify the description only for a specific category.
function weplugins_custom_category_description($description, $category) { if ($category->slug == 'specific-category') { $description .= '<p>This is a special category!</p>'; } return $description; } // Add the action add_action('category_description', 'weplugins_custom_category_description', 10, 2);
Example 3: Removing the Hook
Sometimes, you need to remove a previously added hook. Here’s how you can remove the `category_description` hook.
// Remove the action remove_action('category_description', 'weplugins_execute_on_category_description_event', 10, 2);
That’s it! You’ve now seen how to add, modify, and remove hooks in WordPress. If you need any further customization, feel free to reach out to us.
Contact Us
If you need customization or have any questions, please contact us. We’re here to help!
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.