• Resolved Angelo Rocha

    (@angelorocha)


    After switch theme, the custom logo lost.
    For solve this problem, i try insert a theme mod on switch_theme action, but no success.

    After switch a theme, is possible insert a theme mod for new switched theme?

    My function:

    function rock_theme_switch_logo() {
    	if ( has_custom_logo() ) {
    		$custom_logo_id = get_theme_mod( 'custom_logo' );
    		set_theme_mod( 'custom_logo', $custom_logo_id );
    	}
    }

    Tried with both actions:

    add_action( 'after_switch_theme', 'rock_theme_switch_logo' );

    add_action( 'switch_theme', 'rock_theme_switch_logo' );

    Note: I’m puting this code on my theme functions.php

    Any Idea?

    • This topic was modified 4 years, 2 months ago by Angelo Rocha.
    • This topic was modified 4 years, 2 months ago by Angelo Rocha.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator t-p

    (@t-p)

    After switch theme, the custom logo lost…

    I recommend asking in your new theme’s support so the theme’s developers and support community can help you with this.

    Thread Starter Angelo Rocha

    (@angelorocha)

    I close this thread and open in another forum?

    • This reply was modified 4 years, 2 months ago by Angelo Rocha.
    Thread Starter Angelo Rocha

    (@angelorocha)

    This code is not a theme, I am trying to solve a problem that happens with any theme, it is a specific situation.

    Thread Starter Angelo Rocha

    (@angelorocha)

    My solution, i don’t know if this is a best way.
    In case anyone need.

    /**
     * Keep logo after switch theme
     */
    add_action( 'init', 'rock_theme_keep_logo' );
    function rock_theme_keep_logo() {
    	/**
    	 * Check if custom logo exists
    	 */
    	if ( has_custom_logo() ) {
    		$custom_logo_id = get_theme_mod( 'custom_logo' );
    		/**
    		 * Store custom logo id in a option
    		 */
    		if ( ! get_option( 'rock_custom_logo_temp' ) ) {
    			add_option( 'rock_custom_logo_temp', $custom_logo_id, '', 'no' );
    		}
    	}
    }
    
    /**
     * After theme switch, keep logo
     */
    add_action( 'after_switch_theme', 'rock_keep_logo_after_switch_theme' );
    function rock_keep_logo_after_switch_theme() {
    	if ( ! has_custom_logo() ) {
    		if ( get_option( 'rock_custom_logo_temp' ) ) {
    			set_theme_mod( 'custom_logo', get_option( 'rock_custom_logo_temp' ) );
    		}
    	}
    }
    Moderator t-p

    (@t-p)

    Glad you got it sorted ??

    Thread Starter Angelo Rocha

    (@angelorocha)

    Yes.
    This is a solution to child themes, when a theme have more one child, this problem appears.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Set theme mod after switch theme’ is closed to new replies.