WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] blog info doesn't work (6 posts)

  1. fatty123
    Member
    Posted 2 years ago #

    Hi i'm new to wordpress and php, i try adding a bloginfo to link to my picture but doesnt seem to be working, please help.

    <?php if (!is_page( 24 )){ 
    
            echo "<div id=\"header3\">"; 
    
                 echo "<div id='coin-slider' style=\"position:relative; top:30.33px; z-index:-10; \">";
                 echo "<a href=\"img01_url\" target=\"_blank\">";
                 	echo "<img src=\"<?php bloginfo('template_directory'); ?>/images/index/1.jpg\" width=\"1081\" height=\"374\" alt=\"mcec\" />";
    			 echo  "</a>";
    
          	echo "</div>"; } ?><!--end header3-->
  2. That's really convoluted (or I haven't had enough coffee yet).

    Putting the PHP inside an echo like that won't work, plus you want get_bloginfo() instead, and that's been replaced with a more functional get_stylesheet_directory_uri() as well.

    See what I mean about that coffee? ;)

    Try this (untested) code instead. Replace

    echo "<img src=\"<?php bloginfo('template_directory'); ?>/images/index/1.jpg\" width=\"1081\" height=\"374\" alt=\"mcec\" />";

    with

    echo "<img src=\"" . get_stylesheet_directory_uri() . "/images/index/1.jpg\" width=\"1081\" height=\"374\" alt=\"mcec\" />";

    See if that does it for you.

    http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri

  3. alchymyth
    Forum Moderator
    Posted 2 years ago #

    http://codex.wordpress.org/Function_Reference/get_bloginfo

    http://php.net/manual/en/language.operators.string.php

    change the syntax in this line; for example:

    echo "<img src=\"".get_bloginfo('template_directory')."/images/index/1.jpg\" width=\"1081\" height=\"374\" alt=\"mcec\" />";
  4. fatty123
    Member
    Posted 2 years ago #

    Thank you for the solution I finally got it working,
    . get_stylesheet_directory_uri() . and .get_bloginfo('template_directory').
    both works well, but for the sake of clarification, can you explain why
    bloginfo('template_directory') does't work? I thought all 3 of them are the same thing ?

  5. alchymyth
    Forum Moderator
    Posted 2 years ago #

    why bloginfo('template_directory') does't work?

    some WordPress functions echo the result, which means it gets directly output 'to the screen';

    - in WordPress, these functions' names typically, but not always, start with the_functionname() or simply functionmname()

    while other functions return the result, so it is available for string operations, for instance.

    - in WordPress, those functions' names typically, but not always, start with get_functionname() or get_the_functionname()

    to find out more in general, search the web for 'difference between echo and return php'

  6. fatty123
    Member
    Posted 2 years ago #

    Thank you for the explanation =)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags