Site logo

Archived topic

Elements - Block - Content Template - Hooks Missing

5 replies · Started by Pete Williams on March 12, 2023

Viewing posts 1–6 of 6

I've created a 'Block - Content Template' to allow me to control the width of certain pages/posts that are different to those set in the theme customiser options.
The Content Template includes a Container (to control the width) and a Dynamic Content block to pull in the post content. It works perfectly, but it prevents 'Block - Hook' elements that are set to appear at certain Hook locations from displaying.

Is there a simple way to ensure that these hooks continue to display without relying on shortcodes?

If a different approach is required, I'm happy to look into that too.

Basically, I'd just like the posts/pages to work as default with all hooks active, but still be able to select various widths i.e Other than contained and full-width.

Many thanks for your help.

Kind regards,
Pete

Hi Ying,

Thanks for the reply.

I can't get it to work with a Layout Element, either.

If I set the Layout Element to my preferred width, it works great when the Sidebar layout, 'No Sidebars', is selected but becomes too narrow when the Sidebar layout, 'Right Sidebar', is selected. It also prevents the on-page metabox option of Full Width Content Container from working. It limits the Full-Width to the width set in the Layout Element settings.

Without using a Layout Element, the 'Right Sidebar' layout and 'Full Width' Content works great, but then the 'No Sidebars' layout is too wide. I'd rather not have to keep editing an Element to exclude an additional post or page each time I create one that requires the third layout option.

Ideally, I'd like three different layout widths for both posts and pages.

  1. Full-Width - Content (no sidebars) without padding - So I can have full-width sections throughout the page/post and contain other text via container blocks.
  2. Contained (e.g. 1200px) - Content / Sidebar with padding - Typical blog post layout
  3. Contained (e.g. 800px) - Content (no sidebars) with padding - The content will go no wider than the set width

One solution that seems to provide a workaround:

Set up a custom taxonomy that I can apply to individual pages/posts, similar to the on-page metabox options, allowing me to tick a box to exclude the page/post from the layout element. This seems to be a slightly easier way to manage things rather than editing the layout element to exclude an additional page each time I need a full-width post.

This works, but it's not ideal. Is there an easier way to achieve the three layouts selectable via the on-page metabox options rather than constantly editing Elements?

Kind regards,
Pete

Hi there,

most of what the layout metabox / elements do is to a) add a body_class and b) write some CSS to the page.

For example, when you select:
Full Width content it adds the full-width-content body_class.
No Sidebars it adds the no-sidebar body_class

So a simple solution would be to add this CSS:

.no-sidebar:not(.full-width-content) #content {
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

Then when the page has no-sidebar and is not full-width-content it will fix the width to 800px.

The alternative method is one i provide here:

https://generatepress.com/forums/topic/display-rules-to-target-page-options/#post-2366988

Thanks, David.

I'd already set up your alternative method but was trying to apply a simpler method.

I'm embarrassed that I didn't think of the CSS solution.

That's worked a treat.

Thank you!

You're welcome - glad to be of help.

This archived topic is closed to new replies.