Site logo

[Resolved] Current color of a button.

Home Forums Support [Resolved] Current color of a button.

Home Forums Support Current color of a button.

  • This topic has 3 replies, 2 voices, and was last updated 3 years ago by David.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2566372
    Jusung

    Hello. this is about generate block, but I got no solution there.

    I want to make a current color on button according to url.
    Currently, there is no feature for this.

    However, I thought there could be a way to change the color.

    
    add_action( 'init', 'if_url_contains_string' );
    function if_url_contains_string() { 
    $url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    if ( false !== strpos( $url, '/shop' ) ) {
        echo '<style type="text/css">
             .gb-container-ffa8ce99 { background-color: red }
             </style>';
    } else (false !== strpos( $url, '/product-category/모자') ) { 
        echo '<style type="text/css">
             .gb-container-652ad9ca { background-color: red }
             </style>';
    } else (false !== strpos( $url, 'product-category/상의') ) { 
        echo '<style type="text/css">
             .gb-container-5cdc6557 { background-color: red }
             </style>';
    } else (false !== strpos( $url, '/product-category/신발') ) { 
        echo '<style type="text/css">
             .gb-container-64ee13dc { background-color: red }
             </style>';
    }
    }
    

    Unfortunately this doesn’t work..
    If this is something complicated and out of scope of support, it is ok not to answer!
    I can try to figure out slowly alone.

    #2566566
    David
    Staff
    Customer Support

    Hi there,

    in the Customizer > Colors, add a new Color, and give it a name eg. dynamic-color
    this will register a CSS Variable eg. --dynamic-color: #00ff00;

    apply that color to your button.

    Then you can write some CSS to change that color based on a <body> class

    eg. post-type-archive is the body_class for the shop page.

    
    .post-type-archive {
        -dynamic-color: #ff0000;
    }
    

    for a category archive page, you can use its term-{ID} that is on the body_class eg.

    
    .term-23 {
        -dynamic-color: #ff0000;
    }
    

    Just make as many term-{ID} rules as you need.

    #2566742
    Jusung

    Thank you!!

    that really works!

    #2566993
    David
    Staff
    Customer Support

    Glad to he of help

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