• Resolved aonghus

    (@aonghus)


    Hi all.

    I have my child theme set as two column in the customiser. This is site wide.
    Does anyone know how I can have just one column in one page only?

    I would like to change this in php..

    Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • in your child theme, create a custom page template; the example is based on the file loacation and name:
    /template-parts/one-column-page.php

    copy the code from page.php of Twenty Seventeen, just add Template Name: One Column to the commented section at the top of the file; https://developer.www.ads-software.com/themes/template-files-section/page-templates/#creating-custom-page-templates-for-global-use

    in functions.php of your child theme, add:

    add_filter( 'body_class', 'one_column_page_body_classes', 12 );
    
    function one_column_page_body_classes( $classes ) {
        if ( is_page_template( 'template-parts/one-column-page.php' ) && in_array('page-two-column', $classes) ) {
            unset( $classes[array_search('page-two-column', $classes)] );
    		$classes[] = 'page-one-column';
        }
    	return $classes;
    }
    Thread Starter aonghus

    (@aonghus)

    Hi Michael.

    That worked a charm. Thank you!

    I am trying to get my head around filters and hooks in php. In the add_filter command, are – ‘body_class’, ‘one_column_page_body_classes’ actual html classes? And if so, where are they located?

    I would really like to learn how this worked. Thanks,
    Aomghus ‘

    https://developer.www.ads-software.com/reference/functions/body_class/

    'body_class' is a WordPress filter hook, applied in line 770 of
    https://core.trac.www.ads-software.com/browser/tags/4.7.1/src/wp-includes/post-template.php#L570

    ‘one_column_page_body_classes’ is just a function name, which I have made for the example code.

    re filter hooks, see also https://codex.www.ads-software.com/Plugin_API

    Thread Starter aonghus

    (@aonghus)

    Thanks Michael, that is very useful.

    Cheers,
    Aonghus

    Hi Michael

    I would also like to only have a single page – with no columns and text to be full width

    what is the ccs that i could add?

    I have no idea of coding – your help would be much appreciated.

    My website is twenty seventeen as it is – and the images as is – set as feature image

    The problem i have is – the image is full width but the content not

    hope this helps

    Michael, I did exactly as you instructed and did not get a one column result. My site is set to 2 column, I have a page created with no sidebar assigned. I have selected One Column from the template selection on the page editor. I have the custom sidebar plugin and did have a sidebar assigned to the page in question. After un-assigning a sidebar to the page the theme sidebar is showing and I’m still seeing a two column view.

    I’ve thought about empting the theme sidebar, but I have a child front-page.php with the page.php code in it and it pulls the theme sidebar in a frontpage view. Ironically this post gave me that idea and it worked great.

    If I shift template on one page, the other shifts too, so it’t no different from the default one/two column shifter in the theme. Any explanation to that?

    Best regards
    Michael Hvidtfeldt

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Remove two-column display for just a single page’ is closed to new replies.