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.php
file 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_filter
function:
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_filter
function to hook into thesq_title
andsq_description
filters provided by the Squirrly SEO plugin. - Inside the filter functions, we use
get_post_meta
to retrieve the custom SEO title and description stored in the_sq_title
and_sq_description
post 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.php
file or the custom plugin file. - Now, whenever you have a post or page with a custom
_sq_title
or_sq_description
value 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