Remove slider from mobile device for Travelify WordPress theme

Hi
Is it possible to remove the slider from only mobile phones?
Best regards
Daniel

Hi Daniel,

I hope you are well today and thank you for your question.

You can remove the slider from only mobile phones by using the attached small plugin.

In the provided plugin code we have detected using the function wp_is_mobile whether the website is accessed through mobile or not.

Best Regards,
Movin

Hi Movin
Thank you very much for your quick response.
I am not quite sure where I should place the code? In the php file trough child theme or?
Or is it a traditional plugin that should be installed?
Best regards
Daniel

Hi Daniel,

It’s the traditional plugin that should be installed and activated like other WordPress plugins.

Cheers,
Movin

When I am trying to upload the plugin, it says:

Fatal error: Cannot redeclare travelify_featured_post_slider() (previously declared in /home/www/movingto.dk/wp-content/themes/travelify/library/structure/header-extensions.php:327) in /home/www/movingto.dk/wp-content/plugins/colorlib-plugin.php_2-1/colorlib-plugin.php on line 70

Hi Daniel,

It seems sometime the function travelify_featured_post_slider is getting declared first in the Travelify theme therefore we can’t overwrite it in the plugin.

You can just add the following code in the functions.php file of your child theme.

/**
 * display featured post slider
 *
 */
function travelify_featured_post_slider() {

	if( wp_is_mobile() ){
		return;
	}
	global $post;

	global $travelify_theme_options_settings;
  	$options = $travelify_theme_options_settings;

  $travelify_featured_post_slider = '';
	if (!empty( $options[ 'featured_post_slider' ] ) ) {
		$travelify_featured_post_slider .= '
		<section class="featured-slider"><div class="slider-cycle">';
			$get_featured_posts = new WP_Query( array(
				'posts_per_page' 		    => $options[ 'slider_quantity' ],
				'post_type'					    => array( 'post', 'page' ),
				'post__in'		 			    => $options[ 'featured_post_slider' ],
				'orderby' 		 			    => 'post__in',
				'suppress_filters' 	    => false,
				'ignore_sticky_posts' 	=> 1 						// ignore sticky posts
			));
			$i=0; while ( $get_featured_posts->have_posts()) : $get_featured_posts->the_post(); $i++;
				$title_attribute = apply_filters( 'the_title', get_the_title( $post->ID ) );
				$excerpt = get_the_excerpt();
				if ( 1 == $i ) { $classes = "slides displayblock"; } else { $classes = "slides displaynone"; }
				$travelify_featured_post_slider .= '
				<div class="'.$classes.'">';
						if( has_post_thumbnail() ) {

							$travelify_featured_post_slider .= '<figure><a href="' . get_permalink() . '" title="'.the_title('','',false).'">';

							$travelify_featured_post_slider .= get_the_post_thumbnail( $post->ID, 'slider', array( 'title' => esc_attr( $title_attribute ), 'alt' => esc_attr( $title_attribute ), 'class'	=> 'pngfix' ) ).'</a></figure>';
						}
						if( $title_attribute != '' || $excerpt !='' ) {
						$travelify_featured_post_slider .= '
							<article class="featured-text">';
							if( $title_attribute !='' ) {
									$travelify_featured_post_slider .= '<div class="featured-title"><a href="' . get_permalink() . '" title="'.the_title('','',false).'">'. get_the_title() . '</a></div><!-- .featured-title -->';
							}
							if( $excerpt !='' ) {
								$travelify_featured_post_slider .= '<div class="featured-content">'.$excerpt.'</div><!-- .featured-content -->';
							}
						$travelify_featured_post_slider .= '
							</article><!-- .featured-text -->';
						}
				$travelify_featured_post_slider .= '
				</div><!-- .slides -->';
			endwhile; wp_reset_query();
		$travelify_featured_post_slider .= '</div>
		<nav id="controllers" class="clearfix">
		</nav><!-- #controllers --></section><!-- .featured-slider -->';
	}
	echo $travelify_featured_post_slider;
}

I have added the sample child theme containing the above code so you can also use it.

Best Regards,
Movin

Hey Movin
Thank you very much - it worked perfectly!
Is it possible to also remove the menu bar and header only on mobile?
The reason is I want to use a plugin menu bar instead on mobile.
Again, thank you very much for your help
Best Regards
Daniel

…forgot to mention I want to remove the footer only on mobile to - if it is possible?

Hi Daniel,

You are most welcome here :slight_smile:

You can remove the menu bar, header and footer only on mobile by adding the following code in the functions.php file of your child theme.

function remove_travelify_actions(){

if( wp_is_mobile() ){
	remove_all_actions( 'travelify_header' );
	remove_all_actions('travelify_footer');
}
}
add_action('init', 'remove_travelify_actions');

Cheers,
Movin

Thank you very much, Movin… really appriciate your help - it worked and made the mobile UI pretty!
Best regards
Daniel

Hi again! One last question: Is it possible also to remove the sidebar on mobile that are shown after the posts in the bottom? :slight_smile:

Hi Daniel,

The footer sidebar is already gets removed from the previously shared code.

Now do you want to remove Left Sidebar or Right Sidebar for mobile devices?

Regards,
Movin

Sorry, yeah I meant the right sidebar!
Is it possible to remove only on mobile phones?
Best Regards
Daniel

Hi Daniel,

You can also remove right sidebar only on mobile phones by using the following code replacing previously provided code.

function remove_travelify_actions(){

	if( wp_is_mobile() ){
		remove_all_actions( 'travelify_header' );
		remove_all_actions('travelify_footer');
		remove_all_actions( 'travelify_right_sidebar' );
	}
}
add_action('init', 'remove_travelify_actions');

Cheers,
Movin

Thank you so much, it worked out!
:slight_smile:
Have a nice day!

You are most welcome here :slight_smile:

Hi Movin,

I try to download your plugin for remove siderbar on mobile bot the link not working. Can u help me please with another link for download?

@infalextrac They are working fine for me and getting downloaded.

For your convenience i am sharing them on Google Drive on the following links.

https://drive.google.com/file/d/0B7X-aZPqO9LzclktaXpvTnMzNUU/view?usp=sharing
https://drive.google.com/file/d/0B7X-aZPqO9Lza2ZEZWg0Y2hJc3M/view?usp=sharing