Hook Squirrly Title & Description With Custom Data
To customize the Squirrly SEO Title and Description with data from wp_postmeta using the provided hooks, you can follow these steps:
- Open your theme’s
functions.phpfile or a custom plugin file where you want to add these filters. - Add the following code to customize the Squirrly SEO Title and Description using the
add_filterfunction:
For Title:
add_filter('sq_title', function ($title){
global $post;
if ($custom = get_post_meta($post->ID, '_sq_title', true)) {
return $custom;
}
return $title;
}, 11);For Description:
add_filter('sq_description', function ($description){
global $post;
if ($custom = get_post_meta($post->ID, '_sq_description', true)) {
return $custom;
}
return $description;
}, 11);Explanation:
- We use the
add_filterfunction to hook into thesq_titleandsq_descriptionfilters provided by the Squirrly SEO plugin. - Inside the filter functions, we use
get_post_metato retrieve the custom SEO title and description stored in the_sq_titleand_sq_descriptionpost meta fields, respectively. - We check if a custom title or description exists. If it does, we return the custom value; otherwise, we return the original title or description.
- We set the priority of the filter to 11 to ensure that it runs after the default Squirrly SEO filter.
- Save your
functions.phpfile or the custom plugin file. - Now, whenever you have a post or page with a custom
_sq_titleor_sq_descriptionvalue in the post meta, it will override the default SEO title and description provided by the Squirrly SEO plugin.
Make sure that you have the Squirrly SEO plugin installed and activated for these filters to work, as they rely on the plugin’s filters and functionality.

0 Comments