Mark Anthony
Mark Anthony

Reputation: 127

Hi about wordpress require_once

I want to seperate my files and organize it by not putting them in the function.php I did this.

function required_theme_files() {
	require_once( get_template_directory() . '/inc/customize/color.php' );
	require_once( get_template_directory() . '/inc/sidebar.php' );
}
add_action( 'init', 'required_theme_files' );

but the sidebar.php doesn't work at all can't seem to know the problem I'm not really a programmer more of a front end designer.

function ounox_widget_setup() {
   
	register_sidebar(
		array(
			'name' => 'Sidebar',
			'id' => 'sidebar-1',
			'class' => 'custom',
			'description' => 'Standard Sidebar',
			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
			'after_widget'  => '</aside>',
			'before_title'  => '<h6 class="widget-title">',
			'after_title'   => '</h6>',
		)
	);

}
add_action( 'widgets_init','ounox_widget_setup' );

Upvotes: 0

Views: 920

Answers (1)

BlueDogRanch
BlueDogRanch

Reputation: 536

Try Debug and see what PHP errors you are getting, such as sidebar.php not being loaded or found. See https://codex.wordpress.org/WP_DEBUG

Add

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false);

in wp-config.php and the debug.log file will be in wp-content.

Change the "display" line to true

define( 'WP_DEBUG_DISPLAY', true);

to dump them to the browser as well as log them.

1) Do you have the opening <?php at the top of sidebar.php?

2) Or, your issue may be the use of get_template_directory. That returns an absolute server path (eg: /home/user/public_html/wp-content/themes/my_theme), not a URI.

In the case of a child theme being used, the absolute path to the parent theme directory will be returned. Use get_stylesheet_directory() to get the absolute path to the child theme directory. See get_stylesheet_directory_uri() | WordPress Developer Resources

Upvotes: 1

Related Questions