• Resolved fatty123

    (@fatty123)


    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-->
Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    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.

    https://codex.www.ads-software.com/Function_Reference/get_stylesheet_directory_uri

    https://codex.www.ads-software.com/Function_Reference/get_bloginfo

    https://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\" />";
    Thread Starter fatty123

    (@fatty123)

    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 ?

    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’

    Thread Starter fatty123

    (@fatty123)

    Thank you for the explanation =)

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘blog info doesn't work’ is closed to new replies.