• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Add a class on only one page using "before_post" hook

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add a class on only one page using "before_post" hook

This topic is: not resolved
  • This topic has 7 replies, 2 voices, and was last updated 12 years, 10 months ago by jorwesflow.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • May 12, 2013 at 8:34 pm #40607
    jorwesflow
    Participant

    As the title states, I'd like to add a class for use on only one page (id is '2') that's placed in the genesis_before_post hook. I tried making something up to put in the child's functions.php file, but it didn't work of course. It looked like this:

     
    `
    add_action( 'genesis_before_post' );
    function add_body_class( $classes ) {
    if ( is_page( '2' ))
    $classes[] = 'blog-page-title';
    return $classes;
    }
    `

    http://projectsacramento.com/
    May 12, 2013 at 11:30 pm #40623
    jorwesflow
    Participant

    Just to clarify, what I'm trying to do is put a title graphic image on the blog page above all the posts. I would use CSS to define that image as a background.

    May 13, 2013 at 12:18 am #40629
    Brad Dalton
    Participant

    Better to use PHP and generate the new div class to style your image using a custom function with conditional tag for the blog page.

    Change the Hook if needed

    Or create a custom widget area in the hook position before posts on the blog page.

    Or simply use a custom blog template and then add your image using the WordPress editor.


    Tutorials for StudioPress Themes.

    May 13, 2013 at 12:49 pm #40705
    jorwesflow
    Participant

    Brad, thanks for the thorough response! I tried the custom function and it didn't do anything. I of course changed the hook to 'genesis_before_post'. I tried switching 'blog' with the page id which is '2' and still nothing.

    Again, all I want to do is generate a new div class on the blog page that hooks on 'genesis_before_post'

    May 13, 2013 at 2:51 pm #40714
    Brad Dalton
    Participant

    I just tested that code again and updated that post so I know it works. Not sure why it doesn't on your site.

    Please paste the code here using opening and closing[ php ] shortcodes so I can take a look.

    Try the genesis_before_loop hook


    Tutorials for StudioPress Themes.

    May 13, 2013 at 5:56 pm #40750
    jorwesflow
    Participant

    Brad, worked perfect! The mistake I was making was using the hook 'genesis_before_post' instead of your suggested 'genesis_before_loop'. I'm not savvy enough to know why, but my guess is that it has something to do with the Blog page containing multiple posts? I should have tried some other hooks and gone with 'before_loop' from the start!

    Also, using the page id '2' instead of 'blog' was a deal breaker as well.

    Thanks again for your time.

    May 13, 2013 at 6:10 pm #40753
    Brad Dalton
    Participant

    Yes. Made it myself when testing the code.

    Also, using the page id ’2′ instead of ‘blog’ was a deal breaker as well.

    Really, So blog worked?


    Tutorials for StudioPress Themes.

    May 13, 2013 at 7:12 pm #40776
    jorwesflow
    Participant

    No, what I meant was 'blog' didn't work, but '2' did.

  • Author
    Posts
Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble