• 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

Creating a custom hook programatically

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 › Creating a custom hook programatically

This topic is: resolved
  • This topic has 3 replies, 2 voices, and was last updated 11 years, 2 months ago by Genesis Developer.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • October 29, 2014 at 9:20 am #129745
    lmartins
    Member

    I was trying to dynamically create markup on my page and run inside that markup a custom hook like this:

    add_action( 'genesis_after', 'mw_add_offcanvas' );
    function mw_add_offcanvas()
    {
        $out = '<div class="shifter-navigation">';
        /**
         * Using this hook:
         * mw_add_offcanvas_sidebar
         * mw_offcanvas_menu
         */
        $out .= do_action( 'mw_inside_offcanvas' );;
        $out .= '</div>';
        echo $out;
    }

    The goal was to then be able to assign widget areas or menus to that hook:

    function mw_add_offcanvas_sidebar() {
        genesis_widget_area( 'sidebar-navigation', array(
          'before' => '<div class="widget-area">',
          'after' => '</div>',
        ) );
    }
    
    add_action( 'mw_inside_offcanvas', 'mw_add_offcanvas_sidebar' );
    

    This actually works although the elements are outputted outside of the markup dinamically generated with the mw_add_offcanvas() function.

    How can I achieve this?

    October 29, 2014 at 9:28 am #129748
    Genesis Developer
    Member

    if you try this then what is happening.

    function mw_add_offcanvas()
    {
        $out = '<div class="shifter-navigation">';
        /**
         * Using this hook:
         * mw_add_offcanvas_sidebar
         * mw_offcanvas_menu
         */
        ob_start();
        do_action( 'mw_inside_offcanvas' );
        $out .= ob_get_contents();
        ob_get_clean();
        $out .= '</div>';
        echo $out;
    }

    Download Genesis Featured Posts Combo Widget | Simple Grid Layouts Plugin for Posts, CPTs and terms
    You can request new tips/help.

    October 29, 2014 at 9:48 am #129750
    lmartins
    Member

    @genwrock, can I just way you are awesome? 🙂
    Thank you som much, that does the trick.

    Many, many thanks!
    Cheers!

    October 29, 2014 at 9:53 am #129754
    Genesis Developer
    Member

    Glad to help you.


    Download Genesis Featured Posts Combo Widget | Simple Grid Layouts Plugin for Posts, CPTs and terms
    You can request new tips/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

© 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