[Resolved] How to assign Masonry only to main blog?

Home Forums Support [Resolved] How to assign Masonry only to main blog?

Home Forums Support How to assign Masonry only to main blog?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #143986
    Antonio

    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?

    #144011
    Tom
    Lead Developer
    Lead Developer

    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/

    #144199
    Antonio

    It works if I disable Masonry in Admin, thanks. Now how to get Masonry for home page latest posts?

    #144307
    Tom
    Lead Developer
    Lead Developer

    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';
    }
    #144560
    Antonio

    Perfect. Thanks.

    #144621
    Tom
    Lead Developer
    Lead Developer

    No worries, glad I could help 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.