Skip to content

Instantly share code, notes, and snippets.

@MichaelVanDenBerg
Last active October 2, 2016 12:51
Show Gist options
  • Save MichaelVanDenBerg/004898e4a5e4aaf00147be07b3e2d9d2 to your computer and use it in GitHub Desktop.
Save MichaelVanDenBerg/004898e4a5e4aaf00147be07b3e2d9d2 to your computer and use it in GitHub Desktop.
Set the content width in pixels and adjust the content width for full width pages.
<?php
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function bookmark_content_width() {
$GLOBALS['content_width'] = apply_filters( 'bookmark_content_width', 800 );
}
add_action( 'after_setup_theme', 'bookmark_content_width', 0 );
/**
* Adjust content_width value for full width page template.
*/
function bookmark_full_width_page_content_width() {
if ( is_page_template( 'page-templates/template-full-width.php' ) ) {
$GLOBALS['content_width'] = apply_filters( 'bookmark_full_width_page_content_width', 1280 );
}
}
add_action( 'template_redirect', 'bookmark_full_width_page_content_width' );
@MichaelVanDenBerg
Copy link
Author

MichaelVanDenBerg commented Oct 2, 2016

See list of action hooks: https://codex.wordpress.org/Plugin_API/Action_Reference

Content width for the full width page can't be adjusted before "parse_query" or after "the_post".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment