Archived topic
Masonry Broken on many category pages
7 replies · Started by Paul on February 19, 2022
if you were to go to a category page, you would see that masonry no longer works. This is because the following classes have been stripped from the following HTML elements...
body: missing the .masonry-enabled class
article: missing the .generate-columns, .grid-50, .grid-sizer classes.
Also, the javascript to make the masonry works is no longer applying on the category pages.
Example pages on my site with the issues I am talking about...
https://www.dailycdev.com/category/jesus/
Also, on the example for the Jesus Category, you will see that the excerpt option is not working for "Jesus Was Born in Bethlehem" as it shows all the content which makes the page look very messy.
I am unable to fix this myself since this is broken in the theme itself. Please look into this.
Hi there,
Can you disable all plugins except GP Premium to test?
Please also completely disable SG Optimizer.
Thanks!
Found the issue. It seems the generatepress is not currently compatible with categories on pages. Wordpress allows us to add categories to pages via PHP or plugin, but generatepress doesn't know what to do with that code and strips out masonry classes from the pages if page categories are found. For example, if I enable the "Category on pages" plugin, the masonry fails. The same happens when I use the PHP code found on this page... https://thewphosting.com/add-categories-tags-pages-wordpress/. I am hoping that generatepress sees this as a bug. I use categories on pages very frequently on my site, so I hope this gets fixed very soon.
Hi there,
GP Blog columns and masonry are only associated to the post type of: post
To enable this on other post types ie. pages you need a couple of PHP Snippets:
Add columns to pages:
https://docs.generatepress.com/article/using-columns-in-the-blog/#adding-columns-to-your-custom-post-type
Add masonry to pages:
https://docs.generatepress.com/article/using-columns-in-the-blog/#adding-masonry-to-your-custom-post-type
In both snippets you will see:
if ( is_post_type_archive( 'portfolio' ) ) {
You need to swap portfolio to page
I've tried both of the following php code options from what you gave me and neither works...
add_filter( 'generate_blog_masonry','tu_portfolio_masonry' );
function tu_portfolio_masonry( $masonry ) {
if ( is_post_type_archive( 'page' ) ) {
return 'true';
}
return $masonry;
}
add_filter( 'generate_blog_columns','tu_portfolio_columns' );
function tu_portfolio_columns( $columns ) {
if ( is_post_type_archive( 'page' ) ) {
return true;
}
return $columns;
}
or...
add_filter( 'generate_blog_masonry','tu_page_masonry' );
function tu_page_masonry( $masonry ) {
if ( is_post_type_archive( 'page' ) ) {
return 'true';
}
return $masonry;
}
add_filter( 'generate_blog_columns','tu_page_columns' );
function tu_portfolio_columns( $columns ) {
if ( is_post_type_archive( 'page' ) ) {
return true;
}
return $columns;
}
This code was added to Code Snippets, along with the plugin, "Add Category to Pages".
However, the category pages with pages and posts are still not in the masonry format and missing the classes in the body and articles for it to work.
Hi Paul,
Can you try this PHP snippet instead?:
add_filter('generate_blog_masonry','generate_blog_enable_post_type_masonry');
function generate_blog_enable_post_type_masonry(){
$type = get_post_type();
if ( 'page' == $type ) {
return 'true';
}
}
I tested this on my site and it’s working from my end: https://share.getcloudapp.com/o0uZw748
Also see: https://share.getcloudapp.com/OAu4DGBJ
Kindly let us know how it goes. Hope to hear from you soon! :)
Thank you Fernando. The following PHP code fixed my issue...
add_filter('generate_blog_masonry','generate_blog_enable_post_type_masonry');
function generate_blog_enable_post_type_masonry(){
$type = get_post_type();
if ( 'page' == $type ) {
return 'true';
}
}
You’re welcome Paul! Glad to be of assistance! Feel free to reach out anytime if you’ll need assistance with anything else. :)