• Resolved lopix

    (@lopix)


    This feels like a stupid question, but I have been trying to figure out a solution for days now.

    I want to put an ad on one page of my blog only. I want the text to show up on only the home page.

    I would love to do it through a widget, but they seem to add text only to the sidebar site-wide.

    I have recently been playing with a javascript to check the URL and write the content only if it is the main page.

    <script type="text/javascript">
    if (document.location.href!= "https://www.jeffreyteam.com/blog/index.php") {
    document.write();
    }
    </script>

    Simple enough, right? It does seem to work, but only for bare text. When I start to add any formatting, it gets strange. Some formatting seems to work, but anything involving CSS positioning (absolute mainly) makes the script crap out and display the text on all pages. If I add a top-margin, then it ****s the whole site.

    Even stranger, if I have a style such as

    <P STYLE="color:#999999; margin-bottom:13px; margin-right:225px; font-size:11px; float:right;">

    and I remove the float, then everything seems to work. But I cannot get the position right. If I try some other code, then the text starts to appear on all pages again. Delete the formatting and it goes back to displaying on one page only.

    I need to be able to format the text so it does not look like crap. Plus add some links.

    Does anyone have any ideas? I can go back to <FONT COLOR="aaaaaa" SIZE="-1"> again if I have to, but that does not help with the positioning.

    I know I am missing something small and stupid… but happy to have it pointed out.

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Do a google on ‘wordpress widget anywhere’ to find how to place a widget anywhere in your theme. Then, you can use a text widget to place the ad.

    Moderator t-p

    (@t-p)

    also, review this WP-Snippet, and see if it helps:

    https://wp-snippets.com/serveral-widget-areas/

    Thread Starter lopix

    (@lopix)

    Thanks for the suggestions, but that is not quite what I am looking to do.

    I want a piece of text to appear only on the main page. I do not need a widget to appear somewhere different. I can get the widget to appear wherever I want, but not to appear in one single spot on one single page.

    Create a new widget area in the template for your front page using the suggestions from above, and use is_front_page() to instantiate the widget only on the front page.

    Thread Starter lopix

    (@lopix)

    vtxyzzy – did your search and it led me to Widget-Logic. That was exactly what I needed. I knew it would be something simple and easy.

    Glad you got it working!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Creating text on one page only’ is closed to new replies.