WordPress.org

Ready to get started?Download WordPress

Forums

How to add static element on front page? (3 posts)

  1. pranzyt
    Member
    Posted 4 years ago #

    Hey there,
    Can anyone suggest me how can I add static element(eg. welcome note..etc)on top of main content bar of my blog homepage.

    and it shud be there in every blog post pages.

    (Just like in blogger where we can "add html element" on top)

    Is it possible? IF yes..do u mind giving me instructions??

    Hoping for positive response
    Ranzyt - new bie

  2. vtxyzzy
    Member
    Posted 4 years ago #

    One way to do this is to create a function, insert_greeting() for example, and insert a call to it in each of your templates just ahead of the loop.

    The function definition would look like this:

    <?php function insert_greeting() {
     global $userdata;
     get_currentuserinfo();
     $name = ($userdata->ID) ? $userdata->display_name : 'Guest';
     echo "<h2>Hello, $name.  Welcome to the site!";
     }
     ?>

    This function would be pasted at the end of the functions.php file in your theme folder. Be sure not to leave any blank lines before or after the definition.

    The function call would look like this:

    <?php insert_greeting(); ?>

    In the default theme template index.php the call would look like this:

    get_header(); ?>
    
       <div id="content" class="narrowcolumn" role="main">
          <?php insert_greeting(); ?>
          <?php if (have_posts()) : ?>
    
             <?php while (have_posts()) : the_post(); ?>
  3. pranzyt
    Member
    Posted 4 years ago #

    Thanx for ur support!!

Topic Closed

This topic has been closed to new replies.

About this Topic