[Support request] How to get a preset colour via php

Home Forums Support How to get a preset colour via php

  • This topic has 1 reply, 2 voices, and was last updated 4 months ago by David.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1508367
    shane

    I made some additional changes to layouts using the hooks from elements. I want to be able to just change the colour via the customiser instead of having to go back into elements and use it. The colour would be the same colour for example as the main navigation. Where are those values created / stored? Or does anyone know the php code to reference / pull that colour so I can simply set a value via <style> in elements which would change its colour everytime I changed the navigation colour?

    #1508634
    David
    Staff
    Customer Support

    Hi there,

    you can use the generate_settings function like so:

    // Generate Custom CSS from existing Customizer settings
    function db_custom_css_output() {
        if ( ! function_exists( 'generate_get_defaults' ) ) {
            return;
        }
    
        $generate_settings = wp_parse_args(
            get_option( 'generate_settings', array() ),
            generate_get_defaults()
        );
    
        if ( ! class_exists( 'GeneratePress_CSS' ) ) {
            return;
        }
    
        if ( ! function_exists( 'generate_get_font_family_css' ) ) {
            return;
        }
    
        $css = new GeneratePress_CSS;
    
        // Get custom CSS properties from database
        // Change Selctor to CSS Class instead of element tag
        // Settings from CSS-output.php 
    
        $css->set_selector( '.hero-background' );
        $css->add_property( 'background-color', esc_attr( $generate_settings['navigation_background_color'] ) );
    
        return apply_filters( 'db_custom_css_output', $css->css_output() );
    }
    
    // Enqueue custom styles within generate-style-inline-css
    add_action( 'wp_enqueue_scripts', function() {
        wp_add_inline_style( 'generate-style', db_custom_css_output() );
    }, 100 );

    For reference:
    https://github.com/tomusborne/generatepress/blob/cd3de8b045136141358cbf273a6efbd9fad3732a/inc/css-output.php#L137-L138

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.