Hello, Newbie with simple question here...
A developer has entered this code for me to display a banner ad on my wordpress page. I want the ad to link to a page. How would I do that with this code?

<div class="head_banner"><img src="<?php bloginfo('template_url'); ?>/images/image.png"></div>

Dani AI

Generated

Wrapping the image in an anchor is exactly what and suggested. Below is a cleaner, WordPress-aware version that adds escaping, accessibility, and child-theme safety — replace the page ID and image filename with your values.

<div class="head_banner">
  <a href="<?php echo esc_url( get_permalink( 123 ) ); ?>" target="_blank" rel="noopener noreferrer">
    <img src="<?php echo esc_url( get_stylesheet_directory_uri() . '/images/image.png' ); ?>"
         alt="Promotional banner"
         width="728" height="90"
         loading="lazy" />
  </a>
</div>

Notes on why this is preferable: get_stylesheet_directory_uri() is child-theme safe (use get_template_directory_uri() only for parent themes). esc_url() prevents malformed or unsafe URLs. Always include a meaningful alt for accessibility and width/height to reduce layout shift; loading="lazy" improves performance for non-critical images. Use target="_blank" plus rel="noopener noreferrer" only when you want the link to open in a new tab; omit target to open in the same tab.

Quick troubleshooting: make sure you put this in a PHP theme file (not a post editor), save the file and clear any caches. Confirm the image exists at the path you used or consider uploading it to the Media Library and using attachment functions (for easier updates). For frequently changing banners, manage via the Customizer, a widget, or a small theme option instead of editing template files directly.

Recommended Answers

All 2 Replies

Something like this

<div class="head_banner"><a href="<?php echo home_url();?>/page"><img src="<?php bloginfo('template_url'); ?>/images/image.png"></a></div>
<div class="head_banner"><a href="<?php echo home_url();?>/page"><img src="<?php bloginfo('template_url'); ?>/images/image.png"></a></div>

yes its the same

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.