Skip to contentSkip to main navigation Skip to footer

Add Custom META Description

With the Squirrly SEO plugin, you can customize the META Description for each URL on your website using the:

  • Squirrly SEO Snippet (You can reach this feature from the Edit Post / Add New Post interface of your WordPress site)
  • Squirrly SEO > Automation > Configuration
This image has an empty alt attribute; its file name is description-automation-1.jpg
  • or by calling the sq_description hook in your code.

To edit the META Description using the SEO Automation follow the instructions detailed here >

To edit the META Description using the sq_description hook, activate Squirrly SEO plugin and add this code in function.php file:

//Hook the Squirrly sq_description
add_filter('sq_description', 'custom_squirrly_description', 11);
function custom_squirrly_description($description) {
    return 'My custom META Description';
}

The code above will show the same description for all the pages on your website.

Another solution is to get the post excerpt or the post content and truncate it:

//Hook the Squirrly sq_description 
add_filter('sq_description', 'custom_squirrly_description', 11);
function custom_squirrly_description($description) {
    global $post;
    return  substr($post->post_content, 0, 280);
}

If you want to change the description only for some post IDs, you can add the hook like:

//Hook the Squirrly sq_description 
add_filter('sq_title', ' custom_squirrly_description ', 11);
function  custom_squirrly_description($description) {
    global $post;
    switch ($post->ID) {
        case 1:
            $description = 'My Description For Post ID 1';  //for post_id = 1
        case 2:
            $description = 'My Description For Post ID 2';   //for post_id = 2
    }
    //return the title
    return $description;
}

How to customize the META Description using the BULK SEO feature from Squirrly >

Was This Article Helpful?