WordPress.org

Ready to get started?Download WordPress

Forums

Twenty Twelve
[resolved] Shortcode in Header But Only on Homepage (9 posts)

  1. tedwards500
    Member
    Posted 1 year ago #

    Hello.

    I am using a child theme of Twenty Twelve, and my site is http://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?

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    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.

  3. tedwards500
    Member
    Posted 1 year ago #

    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?

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    That sounds like a promising approach...

  5. tedwards500
    Member
    Posted 1 year ago #

    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?

  6. esmi
    Forum Moderator
    Posted 1 year ago #

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

  7. tedwards500
    Member
    Posted 1 year ago #

    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?

  8. esmi
    Forum Moderator
    Posted 1 year ago #

  9. tedwards500
    Member
    Posted 1 year ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic

Tags

No tags yet.