• 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

Execute actions inside shortcode

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 › Execute actions inside shortcode

This topic is: not resolved

Tagged: shortcode

  • This topic has 5 replies, 3 voices, and was last updated 10 years, 8 months ago by Carlo.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • December 29, 2014 at 7:24 am #135532
    fleea
    Member

    Hi,

    I'm trying to execute actions inside shortcode.
    So here's what I want:
    If there's shortcode in content [content_before_header]$content[/content_before_header]
    I'd like wordpress/genesis to inject $content in the area genesis_before_entry

    Here's my functions:

    add_shortcode('content_before_header', 'insertContentBeforeHeader');
    function insertContentBeforeHeader($atts, $content = null){
      add_action('genesis_before_entry', 'add_content_before_header' );
    }
    
    function add_content_before_header($atts, $content = null){
      echo do_shortcode($content);
    }

    But somehow any add_action inside shortcode is not executed. Any idea how to solve this?

    December 29, 2014 at 10:23 am #135552
    Genesis Developer
    Member

    this will not work. You can't pass the variable in hook function. Can you explain your requirement briefly?


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

    December 29, 2014 at 10:26 am #135555
    fleea
    Member

    Yes, I would like to include some images, google maps and/or extra text above the header, or above menu.
    I just would like to avoid the needs to make templates for each one. That would be so handy if I could execute the add_action and remove_action inside a shortcode.

    December 29, 2014 at 10:49 am #135560
    Genesis Developer
    Member

    Ok. Use Advanced Custom field plugin. You can easily create some custom fields for page template by this plugin. next call the hook from functions.php file and display the content based on this custom fields' value. So you do not need any shortcode or new templates for every pages.


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

    December 30, 2014 at 4:07 am #135651
    Carlo
    Member

    The reason it doesn't work is that you're hooking too late. The genesis_before_entry hook has already been and gone once your content is processed for shortcodes.

    You will need to use Advanced Custom Fields, create a text or wysiwyg field. Then in your theme functions you might have something like this:

    add_action( 'genesis_before_entry', function() {
      the_field( 'your_field_name' );
    } );

    Comprehensive, easy to follow Genesis documentation

    March 5, 2015 at 4:44 am #143279
    Carlo
    Member

    I recently published a tutorial on this topic:
    http://carlomanf.id.au/content-above-header/


    Comprehensive, easy to follow Genesis documentation

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 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

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