Create Full Width on Templates

I created a few templates, and I need all of them to be full width. In the functions.php, I found where it’s defining the width, and inserting bootstrap classes for the full-width template. So in my child functions.php I created this:

/**
 * Set the content width for full width pages with no sidebar.
 */
function ofsd_content_width() {
  if ( is_page_template( 'page-aes.php' ) ) {
    global $content_width;
    $content_width = 1008; /* pixels */
  }
}
add_action( 'template_redirect', 'ofsd_content_width' );

if ( ! function_exists( 'ofsd_main_content_bootstrap_classes' ) ) :
/**
 * Add Bootstrap classes to the main-content-area wrapper.
 */
function ofsd_main_content_bootstrap_classes() {
	if ( is_page_template( 'page-aes.php' ) ) {
		return 'col-sm-12 col-md-12';
	}
	return 'col-sm-12 col-md-8';
}
endif; // sparkling_main_content_bootstrap_classes

But for some reason, it’s not working. Here is a page where I’m using the template: http://778.b98.myftpupload.com/schools/abrams-elementary-school/
Any ideas?

Hi @packerlandwebsites,

I hope you are well today and thank you for your question.

Please try replacing your above shared code with the following code and make sure you have created the template file page-aes.php in the root directory of your child theme.


/**
 * Set the content width for full width pages with no sidebar.
 */
function ofsd_content_width() {
  if ( is_page_template( 'page-aes.php' ) ) {
    global $content_width;
    $content_width = 1008; /* pixels */
  }
}
add_action( 'template_redirect', 'ofsd_content_width' );

/**
 * Add Bootstrap classes to the main-content-area wrapper.
 */
function sparkling_main_content_bootstrap_classes() {
	if ( is_page_template( 'page-fullwidth.php' ) || is_page_template( 'page-aes.php' ) ) {
		return 'col-sm-12 col-md-12';
	}
	return 'col-sm-12 col-md-8';
}

Best Regards,
Movin

That worked perfect, Thank You!

Along those same lines, I have multiple templates. I’m fairly new to php, so is it possible to:
if ( is_page_template( ‘page-aes.php’, ‘page-ofhs.php’ ) ) {
or

elseif ( is_page_template( 'page-ofhs.php' ) ) {
    global $content_width;
    $content_width = 1008; /* pixels */
  }

Nevermind, I figured it out. Thanks again for all your help! :slight_smile:

/**
 * Set the content width for full width pages with no sidebar.
 */
function ofsd_content_width() {
  if ( is_page_template( 'page-aes.php' ) || is_page_template( 'page-ofes.php' ) || is_page_template( 'page-ofhs.php' ) || is_page_template( 'page-wms.php' ) ) {
    global $content_width;
    $content_width = 1008; /* pixels */
  }
}
add_action( 'template_redirect', 'ofsd_content_width' );

/**
 * Add Bootstrap classes to the main-content-area wrapper.
 */
function sparkling_main_content_bootstrap_classes() {
	if ( is_page_template( 'page-fullwidth.php' ) || is_page_template( 'page-aes.php' ) || is_page_template( 'page-ofes.php' ) || is_page_template( 'page-ofhs.php' ) || is_page_template( 'page-wms.php' ) ) {
		return 'col-sm-12 col-md-12';
	}
	return 'col-sm-12 col-md-8';
}

You are most welcome here :slight_smile: