Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add class to .site-inner only on certain pages based on custom body class.
- This topic has 14 replies, 2 voices, and was last updated 6 years, 11 months ago by
asbilly92.
-
AuthorPosts
-
December 16, 2016 at 2:48 pm #197702
asbilly92
ParticipantUsing a filter or hook...
I would like to add a class to the .site-inner but only on specific pages, possibly using the custom body class I made with a filter or hook... ( I don't want it to affect all pages with that page template only a few) Can I use a filter SIMILAR this one but instead target the page via custom body class? This example uses the page template to target it....not what I need; or maybe this will work, need a little help getting it figured out!
Something like this:
add_filter( 'genesis_attr_site-inner', 'custom_add_css_attr' ); function custom_add_css_attr( $attributes ) { if ( is_page_template( 'page_blog.php' ) ) { $attributes['class'] .= ' new-custom-class-here'; } return $attributes; }
December 16, 2016 at 3:13 pm #197703Victor Font
ModeratorInstead of is_page_template you can use is_page ( array( '1', '2', '3', '4') ) where the numbers are the page_ids.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?December 16, 2016 at 3:31 pm #197706asbilly92
ParticipantOk great so my possible corrected filter may look like this:
add_filter( 'genesis_attr_site-inner', 'custom_add_css_attr' ); function custom_add_css_attr( $attributes ) { if ( is_page ( array('1','2','3' ) ) { $attributes['class'] .= ' new-custom-class'; } return $attributes; }
I kind of realized that the page_template one was wrong lol..
December 16, 2016 at 7:06 pm #197713Victor Font
ModeratorYes, you just need to use the correct page ids.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?December 17, 2016 at 7:47 am #197729asbilly92
ParticipantOh yes, of course. I will give it a shot!
Thank you very much! 🙂
December 19, 2016 at 9:31 am #197828asbilly92
ParticipantVictor,
This is what I added and DreamWeaver says there is a problem; on the line that contains the is_page. Do you know why?
add_filter( 'genesis_attr_site-inner', 'custom_add_css_attr' ); function custom_add_css_attr( $attributes ) { if ( is_page ( array('10','140' ) ) { $attributes['class'] .= 'blurr-effect'; } return $attributes; }
December 19, 2016 at 9:51 am #197829asbilly92
ParticipantDoes it make a difference that I'm using a Child Theme ?
December 19, 2016 at 1:00 pm #197832Victor Font
ModeratorThere shouldn't be a space between is_page and the opening paren.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?December 19, 2016 at 5:26 pm #197847asbilly92
ParticipantOh geeze, I stared at that thing for a long time!
December 20, 2016 at 11:54 am #197905asbilly92
ParticipantUggg I'm still getting an error on that same line, I removed the space where you advised me too; but still get an error . . . frustrating 😉
//* For adding class to site inner on certain pages add_filter( 'genesis_attr_site-inner', 'custom_add_css_attr' ); function custom_add_css_attr( $attributes ) { if ( is_page( array('10','140') ) { $attributes['class'] .= ' blurr-effect'; } return $attributes; }
December 20, 2016 at 12:42 pm #197913Victor Font
ModeratorLet's try it this way:
//* For adding class to site inner on certain pages add_filter( 'genesis_attr_site-inner', 'custom_add_css_attr' ); function custom_add_css_attr( $attributes ) { $pages = array( '10', '140' ); if ( is_page( $pages ) { $attributes['class'] .= ' blurr-effect'; } return $attributes; }
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?December 20, 2016 at 2:41 pm #197925asbilly92
ParticipantOk wow great, thank you ! Will try later and post back!
December 21, 2016 at 7:29 am #197939asbilly92
ParticipantOK .... well now it's giving me an error on the line: if ( is_page( $pages ) {
Gotta luv php.....
December 21, 2016 at 2:21 pm #197959Victor Font
ModeratorSorry, missing another ). Here's the corrected code:
//* For adding class to site inner on certain pages add_filter( 'genesis_attr_site-inner', 'custom_add_css_attr' ); function custom_add_css_attr( $attributes ) { $pages = array( '10', '140' ); if ( is_page( $pages ) ) { $attributes['class'] .= ' blurr-effect'; } return $attributes; }
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?December 22, 2016 at 7:38 am #197999asbilly92
ParticipantOh man I should have actually caught that too, wow ok cool!
It works! Perfect!
Thank you for all of your effort!!
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.