• 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

Recognising individual page blocks in PHP code

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 › General Discussion › Recognising individual page blocks in PHP code

This topic is: not resolved

Tagged: Blocks, Gutenberg, lazy blocks, meta, php, snippets

  • This topic has 3 replies, 3 voices, and was last updated 3 years, 9 months ago by jroberts.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • June 23, 2019 at 6:35 pm #491863
    jroberts
    Member

    Hi! I'm very new to coding, but was wondering if anyone could help me with getting an if( statement to work in PHP.

    Using the Lazy Blocks plugin, I've created a block ("Meta Information") that places meta data (authors, data etc.) in the body of the post.

    Meanwhile, I'm using a StudioPress snippet -

    remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );

    - to hide the naturally occurring meta data in the post.

    The problem arises in that I don't want to apply this snippet to all of my posts. I have a huge backlog of posts for which it would be impossible for me to manually apply this information block in order to display the meta.

    As a solution, I wondered if I could create an if( statement before, testing first whether the block exists before applying the snippet.

    Unfortunately, i don't know how to refer to the block (or if it's even possible to refer to it) in an if( command.

    Could anyone help with this? My own attempts at figuring out the block have all failed!

    http://exeposetest1.wpengine.com/
    June 23, 2019 at 6:54 pm #491866
    Anita
    Keymaster

    That might be a better question on the Lazy Blocks plugin support page. They could probably tell you how to target that.


    Love coffee, chocolate and my Bella!

    June 24, 2019 at 5:36 am #491875
    Victor Font
    Moderator

    You're question is unclear and confusing. While I know that you understand what you're saying, to a reader, the way you reference blocks, snippets, and information without context will lead to wrong answers. For example:

    The problem arises in that I don't want to apply this snippet (Assume you mean the remove post info) to all of my posts. I have a huge backlog of posts for which it would be impossible for me to manually apply this information block (What information block? There's no context) in order to display the meta (Assume Lazy Blocks).

    As a solution, I wondered if I could create an if( statement before, testing first whether the block exists (What block? Lazy Blocks or Genesis post info?) before applying the snippet.

    Unfortunately, i don't know how to refer to the block (Which block? Lazy Block or Genesis Post Info?) (or if it's even possible to refer to it) in an if( command.

    The Genesis Post info details are not saved with the post content. It is rendered at run time as the post header is processed in the WordPress loop. There is nothing to reference until the content is fully rendered and ready to send to the browser. The only way to reference remove post info from a group of posts is to wrap your code in a WordPress conditional: https://codex.wordpress.org/Conditional_Tags


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    June 24, 2019 at 6:28 am #491877
    jroberts
    Member

    My apologies; I assumed that referring to "snippet" and "information block" would indicate the only snippet and information block I referred to in the question. Apparently not. The Genesis info itself isn't a block in Gutenberg, or at least as far as the editor would indicate.

    Nonetheless, thank you for showing me WordPress conditionals. I might try to make the Genesis Post info appear only when the Lazy Block isn't present, though my question referred to the Lazy Block. I understand if this is a Catch-22, given that both are presumably rendered at the same time.

    I've posted on Lazy Blocks support, to see if they can offer any more help!

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘General Discussion’ 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

© 2023 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