• Hi. I am using storefront with with a header metaslider (echo do_shortcode(“[metaslider id=30]”); ) – but struggle to get a meta slider to show on on specific pages.

    How can that be solved?

    I have tried with code from this page:

    My page seems to fail when i try to use the if else statement for storefront, code:


    if (is_home() || is_front_page()) : echo do_shortcode(“[metaslider id=123]”); // This is the homepage, replace 123 with your slideshow ID
    elseif ( is_page(‘page-slug’)) : echo do_shortcode(“[metaslider id=123]”); // Replace page-slug and 123 with your specific page slideshow ID respectively
    elseif ( is_page(‘another-page-slug’,’or-this-page’,’Or by page title’)) : echo do_shortcode(“[metaslider id=123]”); // You can add as many other pages as you like
    elseif ( ! empty( $header_image ) ) : ?>

Viewing 15 replies - 1 through 15 (of 18 total)
  • Hi there,

    That code is specifically for the Twenty Twelve theme.

    Try using this code instead:

    <?php
    
    if ( is_front_page() && is_home() ) {
      // Default homepage
    } elseif ( is_front_page() ) {
      // static homepage
      echo do_shortcode("[metaslider id=123]"); // Replace 123 with the slider ID to display on the homepage
    } elseif ( is_home() ) {
      // blog page
    } elseif ( is_page('page-slug') ) {
      // page with slug page-slug
      echo do_shortcode("[metaslider id=123]"); // Replace page-slug and 123 with your specific page
    } elseif ( is_page('another-page-slug','or-this-page','Or by page title') ) {
      // page with slug page-slug
      echo do_shortcode("[metaslider id=123]"); // You can add as many other pages as you like
    }
    
    ?>

    Many thanks,
    Dave

    Thread Starter universalius

    (@universalius)

    Hi Matcha. Thanks for the code, but it only seem to work for my frontpage. I assume the slug-page, is what I define in wordpress backend, inside Pages > “quick edit” specific page > “Slug” name?s

    I then pasted the slug name into the code as seen below. However, the metaslider id=174 slider is not showing under my Product page. Can you tell why?

    ——————–
    <?php

    if ( is_front_page() && is_home() ) {
    // Default homepage
    } elseif ( is_front_page() ) {
    // static homepage
    echo do_shortcode(“[metaslider id=30]”); // Replace 123 with the slider ID to display on the homepage
    } elseif ( is_home() ) {
    // blog page
    } elseif ( is_page(‘siloprodukter’) ) {
    // page with slug page-slug
    echo do_shortcode(“[metaslider id=174]”); // Replace page-slug and 123 with your specific page
    } elseif ( is_page(‘another-page-slug’,’or-this-page’,’Or by page title’) ) {
    // page with slug page-slug
    echo do_shortcode(“[metaslider id=123]”); // You can add as many other pages as you like
    } ?>
    ————–

    Kind regards!

    Thread Starter universalius

    (@universalius)

    The first part of the code, does work for my frontpage, but the elseif statements dont go through. I have even tried using: is_page(‘page_id=5’)

    Have you got an idea whats wrong?

    Try using just this code to test, it should display slider 174 on the page where ID = 5:

    <?php
    if ( is_page( 5 ) ) {
    echo do_shortcode(“[metaslider id=174]”);
    }
    ?>

    Thanks,
    Dave

    Thread Starter universalius

    (@universalius)

    Hi Dave. I have tried with the code above and onto different places of my header.php, but unfortunately there is no slider showing. No output at all.

    Any other adeas?

    Perhaps it’s worth trying with a slider that you know if definitely working i.e. the one that you have got displayed on the homepage?

    Also double check the Page ID.

    Make sure you’re editing the correct template too – perhaps make a subtle change to confirm?

    Thread Starter universalius

    (@universalius)

    There is still no slider showing on other pages than the frontpage. I made sure my permalinks was ok and I am using “page_id=5 for my product page. THe stylesheet is the same, with the same header-file. It seems very strange. Can you see any errors in the header.php here? Is there a way that i can use the functions.php for pasting the slider code instead?

    <?php
    /**
    * The header for our theme.
    *
    * Displays all of the <head> section and everything up till <div id=”content”>
    *
    * @package storefront
    */
    ?><!DOCTYPE html>
    <html <?php language_attributes(); ?> <?php storefront_html_tag_schema(); ?>>
    <head>
    <meta charset=”<?php bloginfo( ‘charset’ ); ?>”>
    <meta name=”viewport” content=”width=device-width, initial-scale=1″>
    <link rel=”profile” href=”https://gmpg.org/xfn/11″&gt;
    <link rel=”pingback” href=”<?php bloginfo( ‘pingback_url’ ); ?>”>

    <?php wp_head(); ?>
    </head>

    <body <?php body_class(); ?>>
    <div id=”page” class=”hfeed site”>
    <?php _e( ‘Skip to content’, ‘storefront’ ); ?>

    <?php
    do_action( ‘storefront_before_header’ ); ?>

    <header id=”masthead” class=”site-header” role=”banner” <?php if ( get_header_image() != ” ) { echo ‘style=”background-image: url(‘ . esc_url( get_header_image() ) . ‘);”‘; } ?>>
    <div class=”col-full”>

    <?php
    /**
    * @hooked storefront_social_icons – 10
    * @hooked storefront_site_branding – 20
    * @hooked storefront_secondary_navigation – 30
    * @hooked storefront_product_search – 40
    * @hooked storefront_primary_navigation – 50
    * @hooked storefront_header_cart – 60
    */
    do_action( ‘storefront_header’ ); ?>

    </div>
    </header><!– #masthead –>
    <?php

    if ( is_front_page() && is_home() ) {
    // Default homepage
    } elseif ( is_front_page() ) {
    // static homepage
    echo do_shortcode(“[metaslider id=30]”); // Replace 123 with the slider ID to display on the homepage
    } elseif ( is_home() ) {
    // blog page
    } elseif ( is_page(‘page_id=5’) ) {
    // page with slug page-slug
    echo do_shortcode(“[metaslider id=228]”); // Replace page-slug and 123 with your specific page
    } elseif ( is_page(‘page_id=5’) ) {
    // page with slug page-slug
    echo do_shortcode(“[metaslider id=228]”); // You can add as many other pages as you like
    }

    ?>

    <?php
    /**
    * @hooked storefront_header_widget_region – 10
    */
    do_action( ‘storefront_before_content’ ); ?>

    <div id=”content” class=”site-content”>
    <div class=”col-full”>

    <?php
    /**
    * @hooked woocommerce_breadcrumb – 10
    */
    do_action( ‘storefront_content_top’ ); ?>

    Hi there,

    it’s looks like you’re using:

    if ( is_page(‘page_id=5’) ) { … }

    I think it should be:

    if ( is_page( 5 ) ) { … }

    https://codex.www.ads-software.com/Function_Reference/is_page

    Did you try using just this:

    <?php
    if ( is_page( 5 ) ) {
    echo do_shortcode(“[metaslider id=174]”);
    }
    ?>

    Thanks,
    Dave

    Thread Starter universalius

    (@universalius)

    Hi Dave. Thanks for the code. As you pointed out, the problem is more related to the use of a different header.php file for woocommerce. Its placed inside /themes/inc/structure/header.php, but it seems like this file cannot be override from a child header. Is there actually a way to make slider appear on the storefron/woocommerce product page?

    Kind regards

    Thread Starter universalius

    (@universalius)

    …I should point out that the below code you gave me, IS WORKING for other no woocommerce related pages. It’s only my product page which is struggling.

    <?php
    
    if ( is_front_page() && is_home() ) {
      // Default homepage
    } elseif ( is_front_page() ) {
      // static homepage
      echo do_shortcode("[metaslider id=123]"); // Replace 123 with the slider ID to display on the homepage
    } elseif ( is_home() ) {
      // blog page
    } elseif ( is_page('page-slug') ) {
      // page with slug page-slug
      echo do_shortcode("[metaslider id=123]"); // Replace page-slug and 123 with your specific page
    } elseif ( is_page('another-page-slug','or-this-page','Or by page title') ) {
      // page with slug page-slug
      echo do_shortcode("[metaslider id=123]"); // You can add as many other pages as you like
    }
    
    ?>

    Could I just check which theme you are using?

    It should be a case of creating the same header.php file with the same path in your child theme – did you try that?

    Thanks,
    Dave

    Thread Starter universalius

    (@universalius)

    Sure, I am using storefront with woocommerce. I am not sure what you mean about creating the same header.php file, since the woocommerce header.php cannot be overwritten. Unfortunately. But I have been overwriting my header.php for the storefront theme.

    Hi there,

    Have you tried the woocommerce forums? They might be able to help you more than us, sorry!

    Thanks,
    Dave

    Thread Starter universalius

    (@universalius)

    Thanks Dave. I will try trough there.

    Kind regards

    Mads

    Parse error: syntax error, unexpected ‘child_theme_init’ (T_STRING) in C:\xampp\htdocs\maikaka\wp-content\themes\storefront\functions.php on line 19

    i get this error when ever i put this code in function.php

    add_action( ‘init’, ‘child_theme_init’ );
    fuction child_theme_init() {
    add_action( ‘storefront_before_content’, ‘woa_add_full_slider’, 5 );
    }

    Function woa_add_full_slider() { ?>
    <div id=”slider”>
    <?php echo do_shortcode(“[metaslider id=100 percentwidth=100]”); ?>
    </div>
    <?php>
    }

    pls help me

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Meta slider integration in header for specific pages’ is closed to new replies.