• Resolved MV

    (@mvenkadesan)


    Hi,

    I want to apply appearance customizations within a child theme without having to click through the customize interface. So I would like to do this using hooks and filters within my child theme. For example, I would like to specify the header width as full or contained using code instead of manually. Is there documentation for hooks or filters to accomplish this? I can do this using custom CSS styling, such as,

    
    #masthead {
      max-width: 1200px;
      margin-left: auto;
      margin-right: auto;
    }
    

    Is there a more principled way to do this in order to mimic the customizer?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter MV

    (@mvenkadesan)

    I think I found it, but would like your thoughts if my approach is correct.

    add_filter( 'generate_header_class', 'myname_header_classes' );
    function myname_header_classes( $classes ) {
        $classes[] = 'grid-container';
        if ( ! generate_is_using_flexbox() ) {
            $classes[] = 'grid-parent';
        }
    
        return $classes;
    }

    I have the latest (free) GP theme. So I probably don’t need to check whether flexbox is used. That was a safety check. I used the code in markup.php as a guide to come up with this filter. Does it make sense? Are customizer.php and markup.php the general location to search to see how to implement the customizer functionality using my own hooks?

    Leo

    (@leohsiang)

    Hi there,

    Would this filter help?
    https://docs.generatepress.com/article/option_generate_settings/

    Let me know ??

    Thread Starter MV

    (@mvenkadesan)

    Hi @leohsiang : How fantastic! What a thoughtful hook to provide. Thank you.

    I have one other question. Some of the customizations can be done using custom CSS, a PHP filter, or something nice like option_generate_settings. Are there any performance consequences of one option over the other? More generally, is it better to add custom CSS to my child theme or is it better to use hooks within my child theme’s functions.php? Of course, this question only applies when there are equivalent ways to do this using both means. I love the speed of GP and do not want poor choices to slow it down.

    Leo

    (@leohsiang)

    I would say filters are better than CSS.

    You can always try both methods and compare your site speed ??

    Thread Starter MV

    (@mvenkadesan)

    @leohsiang : I used the following settings and I still see a full width header and the title and tagline are visible. What am I doing wrong?

    add_filter( 'option_generate_settings','mycustom_settings' );
    function mycustom_settings( $options ) {
        $options['hide_title'] = 'true';
        $options['hide_tagline'] = 'true';
        $options['container_width'] = '1200';
        $options['top_bar_width'] = 'contained';
        $options['top_bar_inner_width'] = 'contained';
        $options['top_bar_alignment'] = 'right';
        $options['header_layout_setting'] = 'contained';
        $options['header_inner_width'] = 'contained';
        $options['header_alignment_setting'] = 'left';
        $options['content_layout_setting'] = 'separate-containers';
        $options['footer_layout_setting'] = 'contained-footer';
        $options['footer_inner_width'] = 'contained';
        $options['back_to_top'] = 'enable';
        
        return $options;
    }
    Leo

    (@leohsiang)

    Your return isn’t correct:
    https://www.screencast.com/t/ygTFnUppF4

    Thread Starter MV

    (@mvenkadesan)

    @leohsiang : Thank you. The help from you is so prompt and helpful. That fixed it.

    Thread Starter MV

    (@mvenkadesan)

    Sorry. Forgot to mark as resolved.

    Leo

    (@leohsiang)

    No problem ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Hooks for appearance customizer’ is closed to new replies.