Community Forums › Forums › Archived Forums › General Discussion › Create sidebars outside functions.php via include
Tagged: functions, import, include, sidebars, widget areas
- This topic has 2 replies, 2 voices, and was last updated 8 years, 6 months ago by carasmo.
-
AuthorPosts
-
May 24, 2016 at 2:47 am #186173cliffdemandtMember
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,
CliffMay 24, 2016 at 9:09 am #186186carasmoParticipantThe 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;
May 24, 2016 at 9:11 am #186187carasmoParticipantAlso, 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
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.