WordPress.org

Ready to get started?Download WordPress

Forums

Need code for text to only appear homepage (7 posts)

  1. amomslove
    Member
    Posted 4 years ago #

    I have a blog: http://www.amomslove.com where I want to place an ad in the left hand sidebar. The person prefers to
    only be on my homepage and not all through the site. My sidebar is a widget. What code can I add that lets the her
    link just appear on my home page?

  2. buddha trance
    Member
    Posted 4 years ago #

    You can use conditional tags
    http://codex.wordpress.org/Conditional_Tags

    Try to use this in sidebar.php, after
    <div id="sidebar">

    <?php if (is_home()) {
            echo "<a href='http://www.example.com'><img src='path/to/image/image.jpg'</a>";
    } ?>
  3. amomslove
    Member
    Posted 4 years ago #

    Thank you buddha, but I put this code up..it isn't an image but just a text link...so I put this up but it doesn't seem to work:
    <p align=center>
    <?php if (is_home()) {
    echo "Google";
    } ?>

    http://www.amomslove.com

  4. buddha trance
    Member
    Posted 4 years ago #

    @amomslove - Well, luckily you didn't need an image! I just realized that I didn't close the img tag in the earlier example... [blush]
    it should have been, for those who need an image

    <?php if (is_home()) {
            echo "<a href='http://www.example.com'><img src='path/to/image/image.jpg'></a>";
    } ?>

    for just text, use:

    <p style="text-align:center;">
    <?php if (is_home()) {
            echo "<a href='http://www.example.com'>Example</a>";
    } ?>
    </p>
  5. amomslove
    Member
    Posted 4 years ago #

    Buddha, I put up the second one and it still doesn't work.
    Do you make all your images on your blog? They are incredible.

    AMomsLove.com

  6. buddha trance
    Member
    Posted 4 years ago #

    @amomslove - I see, looked at your source code. That would not work inside a text widget, because there is php code. And you need php to create the conditional tag (since you only want the link in the home page)

    Look at this plugin
    http://wordpress.org/extend/plugins/php-code-widget/

    It works just like a text widget, but it parses php as well.

    The other alternative is to hard code it into the template, sidebar.php

    Re: blog, all theme images are mine, except for post pics. :-)

  7. tracyselena
    Member
    Posted 4 years ago #

    so I want to do something like this as well, but what i want is i have a piece of music that i want to play only on the home page....

    the code i have is this:
    <?php if !(is_home()) {
    <embed src="http://www.atouchoflove.ca/audio/HomeAloneSample.mp3" autostart="true" loop="true" hidden="true">
    } ?>

    is that right? i'm so not a php programmer, but this doesn't work anyways...can you see something that stands out...as to why it won't work?

    i'm putting it in the main index.php file directly under:
    <?php get_header(); ?>

    Please help...Thanks
    tracy

Topic Closed

This topic has been closed to new replies.

About this Topic