• Resolved tedwards500

    (@tedwards500)


    Hello.

    I am using a child theme of Twenty Twelve, and my site is https://verandalane.com/

    I am trying to insert a slider with the Easyrotator plugin using shortcode into header.php. The thing is, I only want it to show on the homepage, and no other pages/posts.

    I have tried the suggestions in this thread, but neither method seems to work.

    I am wondering if it is because of the form of shortcode being used. The examples use ones such as [shortcode], but what I am trying to use is [easyrotator]ID NUMBER[/easyrotator] (one with an opening and closing tag).

    Also, the homepage uses the page-templates/full-width.php template. I am not sure if that matters or effects anything when I use things like is_home().

    Anybody have any suggestions or ideas?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Shortcodes often need to be within Post or Page content to ensure that they are parsed by the_content(), so it is highly unlikely that this is going to work in header.php. Try contacting the plugin’s developer for some suggestions for an alternative solution.

    Thread Starter tedwards500

    (@tedwards500)

    Thanks for the reply.

    The funny thing is, yesterday I was able to get it working to show on all the pages. But today when I do the same thing, it doesn’t seem to work.

    I will start looking at other possible methods. Maybe adding a widget area into the header to use the plugin’s widget?

    That sounds like a promising approach…

    Thread Starter tedwards500

    (@tedwards500)

    So I have gotten a new widget area added and the widget works in the header. This site was very helpful for anybody who is looking to do that.

    I am now back at my original problem of needing it to only show on the homepage.


    <?php if ( is_home() ):?>

    <?php
    if ( dynamic_sidebar('sidebar-8') ) :
    else :
    ?>
    <?php endif; ?>

    <?php endif; ?>

    I tried this, but it doesn’t show up at all. Is there something wrong with the code? Is the page somehow not detected as the homepage anymore because it uses a different template?

    Have you created a template file called sidebar-sidebar-8.php for this new widget ready area?

    Thread Starter tedwards500

    (@tedwards500)

    No. I added it by editing the functions.php file. When I use just this code

    <?php
    if ( dynamic_sidebar('sidebar-8') ) :
    else :
    ?>
    <?php endif; ?>

    it works. It is when I add the parts to display it only on the homepage that it stops showing up.

    I can quickly create another template however. What would be in it?

    Thread Starter tedwards500

    (@tedwards500)

    I got it to work!

    As I was researching, I remembered that I already have a plugin designed just for this purpose (WooSidebars). I couldn’t use it before because it required a widget area to base it off of, and there wasn’t one before.

    Thanks for the tips!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Shortcode in Header But Only on Homepage’ is closed to new replies.