Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] function enqueue depend of dynamic url


  • neoseeyou
    Participant

    @neoseeyou

    Hello there

    I want to enqueue style into a specific sub page /user/profile/change-avatar

    I try several codes like this

    add_action('wp_enqueue_scripts', 'cutting',100);
    
    function cutting() {
    $uri = $_SERVER['REQUEST_URI'];
    if(strpos($uri,'members/'. $current_user->user_login .'profile/change-avatar') == true){
       wp_register_style( 'connected4', get_stylesheet_directory_uri() . '/connected4.css' );
        wp_enqueue_style( 'connected4' );
    }
    }

    Unfortunatly it’s not working.

    Could help me please?
    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)

  • Henry Wright
    Moderator

    @henrywright

    I believe bp_is_change_avatar() is what you are looking for.


    neoseeyou
    Participant

    @neoseeyou

    Hello and thank you

    Still not working!

    add_action('wp_enqueue_scripts', 'cutting',100);
    
    function cutting() {
    $uri = $_SERVER['REQUEST_URI'];
    if(strpos($uri,'members/'. bp_is_user_change_avatar() .'profile/change-avatar') !== false){
       wp_register_style( 'connected4', get_stylesheet_directory_uri() . '/connected4.css' );
        wp_enqueue_style( 'connected4' );
    }
    }

    or

    add_action(‘wp_enqueue_scripts’, ‘cutting’,100);

    function cutting() {
    $uri = $_SERVER[‘REQUEST_URI’];
    if(strpos($uri,’members/’. bp_is_change_avatar() .’profile/change-avatar’) !== false){
    wp_register_style( ‘connected4’, get_stylesheet_directory_uri() . ‘/connected4.css’ );
    wp_enqueue_style( ‘connected4’ );
    }
    }


    neoseeyou
    Participant

    @neoseeyou

    i try with different combinaisons:

    !== false
    ===true (work but too much, it apply this css to /profile/modification or profile too)


    danbp
    Moderator

    @danbp


    Henry Wright
    Moderator

    @henrywright

    You’re not using the function I gave you right. There’s no need to use server variable or do a string replacement.


    neoseeyou
    Participant

    @neoseeyou

    of course i am an idiot ahah

    add_action('wp_enqueue_scripts', 'cutting',100);
    
    function cutting() {
    if(bp_is_change_avatar()){
       wp_register_style( 'connected4', get_stylesheet_directory_uri() . '/connected4.css' );
        wp_enqueue_style( 'connected4' );
    }
    }

    Thank you

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] function enqueue depend of dynamic url’ is closed to new replies.
Skip to toolbar