• I have set the default layout, so that on theme activation the default layouts shows on front-end without having to save anything in the database. But the problem is the default layouts doesn’t show on theme activation. It shows blank page.

    //File - default.php
    <?php function prefix_option_defaults() {
    
    //default values
    $defaults = array(
        'frontpage_layouts' => 'layout_3',
    );
    
      $options = get_option('prefix',$defaults);
    
      //Parse defaults again - see comments
      $options = wp_parse_args( $options, $defaults );
    
    return $options; }

    Calling the defaults at the top of header.php file

    //File - header.php
    global $prefix;
    $prefix= prefix_option_defaults();

    Here’s the code I’m calling the layouts from –

    //File - landing-page.php
    if ( get_option( 'frontpage_layouts' ) === 'layout_1' ) { 
    
           get_template_part( 'frontpage/content', 'cta' ); }
    
        elseif ( get_option( 'frontpage_layouts') === 'layout_2' ) { 
    
            get_template_part( 'frontpage/content', 'cta2' ); }
    
        elseif ( get_option( 'frontpage_layouts' ) === 'layout_3' ) { 
    
            get_template_part( 'frontpage/content', 'cta3' ); } 
    
        else ( get_option( 'frontpage_layouts' ) === NULL ); { 
    
             get_template_part( 'frontpage/content', 'cta3' ); }

    My customizer options are saved as –

    get_option(‘frontpage_layouts’)

    I’d appreciate if anybody can help me

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The blank page might be because of a PHP error somewhere. Define WP_DEBUG as true in your wp_config.php file and try again. You should see an error message this time if that was indeed the problem. If you correct the error, it may be everything will work as expected, except I’m not seeing how your first two snippets have anything to do with the last.

    In the first two you end up with $prefix['frontpage_layouts'] == 'layout_3', but there’s nothing I see getting that to the option ‘frontpage_layouts’. If the option ‘frontpage_layouts’ is set upon activation by some other code, then what is the purpose of getting a value out of the ‘prefix’ option?

Viewing 1 replies (of 1 total)
  • The topic ‘Default Layouts not showing on frontend on theme activation’ is closed to new replies.