• Resolved julianm

    (@julianm)


    Hello! With the following filters, is there a way to specify a custom mobile theme that is located outside the plugin folder, for example, inside the wp-content/themes/ folder?

    add_filter( 'jetpack_mobile_stylesheet', function( $stylesheet, $theme ) {
    	return 'custom/mobile';
    } );
    
    add_filter( 'jetpack_mobile_template', function ( $template, $theme ) {
    	return 'custom/mobile';
    	// if our mobile theme is a child theme, we should return the parent:
    	// return 'pub/myparenttheme-mobile';
    } );

    https://wordpress.org/plugins/jetpack/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    That should work, yes, as long as the string matches your theme’s stylesheet or template value. For a parent theme, the template is the theme’s directory name. For a child theme, the stylesheet is the child theme’s directory name.

    Thread Starter julianm

    (@julianm)

    Hi Jeremy,

    I’ve tried it, but it didn’t seem to work. It seems to default to a path relative to the plugin’s mobile theme folder. What would the string look like if I wanted to use the following path, for example?

    wp-content/themes/mobile/custom/styles.css

    Instead of this one:

    wp-content/plugins/jetpack/modules/minileven/theme/cutom/mobile/style.css

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    What would the string look like if I wanted to use the following path, for example?

    wp-content/themes/mobile/custom/styles.css

    I’d suggest placing your theme in wp-content/themes/mobile/style.css instead, and the template and stylesheet values would then be mobile.

    Thread Starter julianm

    (@julianm)

    Hi Jeremy. If I use just “mobile” as the return string, Jetpack tries to load it from here:

    /wp-content/plugins/jetpack/modules/minileven/theme/mobile/style.css?ver=4.2.1

    add_filter( 'jetpack_mobile_stylesheet', 'mobile_theme_callback' );
    
    add_filter( 'jetpack_mobile_template', 'mobile_theme_callback' );
    
    function mobile_theme_callback(  ) {
    	return 'mobile';
    }

    The only problem with this is that updating the plugin removes the theme directory.

    This can be tested with the jetpack_mobile_stylesheet filter. If testing with jetpack_mobile_template filter, it produces a fatal error.

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    Interesting. It might be a bug with how we define the filter.

    Could you try to prefix things with get_theme_root_uri or get_theme_root, and let me know if one of these help?
    https://codex.wordpress.org/Function_Reference/get_theme_root_uri
    https://codex.wordpress.org/Function_Reference/get_theme_root

    Thread Starter julianm

    (@julianm)

    That didn’t seem to work. Here’s what happens using those two functions…

    add_filter( 'jetpack_mobile_stylesheet', function( $stylesheet, $theme ) {
    	$ss = get_theme_root() . 'mobile';
    	return $ss;
    } );

    Adds the following:

    <link rel='stylesheet' id='style-css'  href='http://www.[DOMAIN].com/cms/wp-content/plugins/jetpack/modules/minileven/theme//home/[USER]/public_html/cms/wp-content/plugins/jetpack/modules/minileven/thememobile/style.css?ver=4.1.4' type='text/css' media='all' />
    add_filter( 'jetpack_mobile_stylesheet', function( $stylesheet, $theme ) {
    	$ss = get_theme_root_uri() . '/mobile';
    	return $ss;
    } );

    Adds the following:

    <link rel='stylesheet' id='style-css'  href='http://www.[DOMAIN].com/cms/wp-content/plugins/jetpack/modules/minileven/theme/http%3A//www.[DOMAIN].com/cms/wp-content/plugins/jetpack/modules/minileven/theme/mobile/style.css?ver=4.1.4' type='text/css' media='all' />
    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    Thanks for giving it a try. That seems like a bug. I took note of it in this GitHub issue:
    https://github.com/Automattic/jetpack/issues/2061

    Feel free to follow our progress there. I’ll also post here when I have some news.

    Thread Starter julianm

    (@julianm)

    Awesome, thank you! I’ve subscribed to the issue on GitHub also.

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

The topic ‘Custom mobile theme’ is closed to new replies.