• 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

Create sidebars outside functions.php via include

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 › Create sidebars outside functions.php via include

This topic is: not resolved

Tagged: functions, import, include, sidebars, widget areas

  • This topic has 2 replies, 2 voices, and was last updated 6 years, 10 months ago by carasmo.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • May 24, 2016 at 2:47 am #186173
    cliffdemandt
    Member

    Hi all,

    Because my functions.php was becoming very large I decided to split it up into seperate documents.
    I made the following structure:

    
    /* IMPORTS -------------------------------------------------------- */
    
    //login screen
    include 'includes/login.php';
    
    //create widgets
    include 'includes/widgets.php';
    
    //blog adjustments
    include 'includes/blog.php';
    
    //Responsive
    include 'includes/responsive.php';
    
    and on...
    

    But when I put the genesis_register_sidebar part in the included widgets.php it does not work.
    I also tried to wrap it in a function but that does not work either.

    includes/widgets.php:

    /** Registreren widget areas **/
    add_action( 'genesis_init', 'create_widgets_areas');
    function create_widgets_areas()
    {
    	genesis_register_sidebar( array(
    		'id'			=> 'search-bar',
    		'name'			=> __( 'Zoekbalk bovenin', 'globeview' ),
    		'description'	=> __( 'Deze widget is voor de zoekbalk prominent op de homepagina.', 'globeview' ),
    	) );
    	genesis_register_sidebar( array(
    		'id'			=> 'home-header-overlay-img',
    		'name'			=> __( 'Home - Overlay', 'globeview' ),
    		'description'	=> __( 'This is the call to action section on the home page.', 'globeview' ),
    	) );
    	
    	genesis_register_sidebar( array(
    		'id'			=> 'laatste-nieuws-large',
    		'name'			=> __( 'Laatste nieuws large', 'globeview' ),
    		'description'	=> __( 'Hier komt het laatste nieuws met grote afbeelding.', 'globeview' ),
    	) );
    	genesis_register_sidebar( array(
    		'id'			=> 'laatste-nieuws-medium',
    		'name'			=> __( 'Laatste nieuws medium', 'globeview' ),
    		'description'	=> __( 'Hier komt het laatste nieuws met middelafbeelding.', 'globeview' ),
    	) );
    	genesis_register_sidebar( array(
    		'id'			=> 'laatste-nieuws-small',
    		'name'			=> __( 'Laatste nieuws small', 'globeview' ),
    		'description'	=> __( 'Hier komt het laatste nieuws met kleine afbeelding.', 'globeview' ),
    	) );
    	genesis_register_sidebar( array(
    		'id'			=> 'testimonials',
    		'name'			=> __( 'Testimonials', 'globeview' ),
    		'description'	=> __( 'Hier komen de testimonials.', 'globeview' ),
    	) );
    	genesis_register_sidebar( array(
    		'id'			=> 'collapsing-categories',
    		'name'			=> __( 'Collapsing categories', 'globeview' ),
    		'description'	=> __( 'Hier komen de categorieën', 'globeview' ),
    	) );
    }

    Can anybody tell me how to create the widgets from an external document which is imported into functions.php?

    Kind regards,
    Cliff

    May 24, 2016 at 9:09 am #186186
    carasmo
    Participant

    The way it is done in WordPress is different. See http://justintadlock.com/archives/2010/11/17/how-to-load-files-within-wordpress-themes and other examples in other themes.

    In a child theme inside an includes directory:

    require_once( trailingslashit( get_stylesheet_directory() ) . '/includes/file-name.php' );

    or, if in the root of the child theme:

    require_once( trailingslashit( get_stylesheet_directory() ) . 'file-name.php' );

    Then in the included file itself use ONE opening php tag, NO closing tag and start it with:

    <?php
    
    /**
     * What is this include about
     *
     * @author      Your Name
     * @copyright   Copyright (c) 2016, Your Name
     * @license     GPL-2.0+
     * @link        ???
     * @version     ???
     *   
     */
     
     
    defined( 'ABSPATH' ) || exit;
    

    Genesis Theme Customization and Help

    May 24, 2016 at 9:11 am #186187
    carasmo
    Participant

    Also, you should take a course in WordPress development or use the Codex because if you work with debug on as is recommended, you would have seen that the files won't be included the way you did it.

    https://codex.wordpress.org/Debugging_in_WordPress


    Genesis Theme Customization and Help

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