• Hi, I’m running a child theme of Superhero (as recommended) and have modded it via the child function to select a ‘No Sidebar’ template via category. e.g.:

    https://www.mutantpop.net/walk/2014/04/08/bourne-end-shiplake/

    One problem I’m having though as you might be able to see with the featured image is the content width, I can only fix this by modding the main theme, which of course gets nuked by updates as I’ve just down now:

    if ( ! isset( $content_width ) )
    	$content_width = 910; /* pixels */
    
    /**
     * Adjust the content width for Full Width page template.
     */
    function superhero_set_content_width() {
    	global $content_width;
    
    	if ( is_page_template( 'page-full-width.php' ) )
    		$content_width = 910;
    	if ( is_post_template( 'single-nosidebar.php' ) )
    		$content_width = 910;
    }
    add_action( 'template_redirect', 'superhero_set_content_width' );

    I’ve tried adding this to my child functions as ‘after_setup_theme’ action, but no joy. Is there a way of modding my child theme to override the content_width setting? It’s obviously needed during the setup somewhere…it also overrides any Settings > Media settings, they don’t seem to make a difference.

    And yes it does work if I mod the main theme functions.php, but updates are going to be a pain with that…(btw I tried your CSS fix mentioned elsewhere…doesn’t work, not the 100% !IMPORTANT – guessing the PHP sets the max width of the featured image via content_width somewhere?

    Thanks

    Tim

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi Tim, could you try adding this to your child theme and let me know if it works to size your images to 910px on a new page or post using those templates?

    <?php
    add_filter('template_redirect', 'custom_content_width_embed_size');
    
    function custom_content_width_embed_size($embed_size){
    	if ( is_page_template( 'page-full-width.php' ) || is_page_template( 'single-nosidebar.php' ) ) {
    	global $content_width;
    	$content_width = 910;
    	}
    }
    ?>
    Thread Starter timbearcub

    (@timbearcub)

    Thanks!

    This worked for the Featured Image (which was fixed by adding the function superhero_setup() to the child function.php), but there isn’t the option for the right size in the size box 910 x etc when you add an image to the post.

    If I change the settings in the main theme, it appears, whereas otherwise with the code above it only shows (645 x )

    The bit that makes the difference is:

    if ( ! isset( $content_width ) )
    $content_width = 910;

    Could you try adding this function to your child theme as well?

    /* Access global variable directly to adjust the content width */
    if ( isset( $GLOBALS['content_width'] ) ) {
    	$GLOBALS['content_width'] = 910;
    }

    It may not change the size of images in existing posts, only applying to newly inserted media.

    Let me know how it goes!

    Thread Starter timbearcub

    (@timbearcub)

    Yes I tried that (I updated the theme which cleared any changes in the parent theme and added that to my child functions.php)

    It still doesn’t show 910x images in the dropdown unless I edit $content_width = 910 in the parent theme. Very odd.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Change content_width (no sidebar) and featured image’ is closed to new replies.