Archived topic
How to assign Masonry only to main blog?
5 replies · Started by Antonio on October 13, 2015
Hello
in my menu I have some category items, I want to use the Masonry option only in a few of them and to let the classical option for th others. Is it possibile?
Hi there,
You can use this function to enable masonry on specific categories:
add_filter('generate_blog_masonry','generate_blog_enable_blog_masonry');
function generate_blog_enable_blog_masonry()
{
// If we're on a category named "Category Name"
if ( is_category('Category Name') )
return 'true';
// If we're on a category named "Sports"
if ( is_category('Sports') )
return 'true';
// If we're on a category named "Tech"
if ( is_category('Tech') )
return 'true';
// Otherwise, disable it
return 'false';
}
Adding PHP: https://generatepress.com/knowledgebase/adding-php-functions/
It works if I disable Masonry in Admin, thanks. Now how to get Masonry for home page latest posts?
Just have to add a is_home() check in there:
add_filter('generate_blog_masonry','generate_blog_enable_blog_masonry');
function generate_blog_enable_blog_masonry()
{
// If we're on the blog
if ( is_home() )
return 'true';
// If we're on a category named "Category Name"
if ( is_category('Category Name') )
return 'true';
// If we're on a category named "Sports"
if ( is_category('Sports') )
return 'true';
// If we're on a category named "Tech"
if ( is_category('Tech') )
return 'true';
// Otherwise, disable it
return 'false';
}
Perfect. Thanks.
No worries, glad I could help :)
