1

I have a help page added to my admin, with screenshots of various config settings.

The screenshots are located in a subfolder (several levels deep) of the theme.

Currently, to insert linked thumbnails I'm using this...

<a href="<?php bloginfo('template_directory')?>/path_to/image.png">
<img src="<?php bloginfo('template_directory')?>/path_to/image.png"></a>

For simplicity, I'm wondering if/how I can use a $variable to set the path to the appropriate subfolder, and use it (rather than the full path).

My limited knowledge is enough to echo such an url...

$url = bloginfo('template_directory'). '/extras/config/screenshots/plugins';

echo $url;

But I don't know enough to use it to add the image and link.

1

You are most of the way there, you simply have to echo it into the include:

<a href="<?php echo $url;?>/image.png"><img src="<?php echo $url;?>/image.png"></a>

If you are already echoing this whole line, then you simply concatenate the variable:

echo '<a href="'.$url.'/image.png"><img src="'.$url.'/image.png"></a>'

Do some reading on PHP "concatenation" :)

  • thanks. I'd tried that initially and it didn't work (still doesn't). I wonder whether it's because I'm 'using php within php' (it's added to a /functions .php file - I'll edit my original post to make clear). – glvr Aug 13 '17 at 8:59
  • I understand, have edited my answer. Of course the paths will have to be correct, but the principle is as I indicated :) – mayersdesign Aug 13 '17 at 9:06
  • thanks. as suggested, I'll read more. The issue I'm getting is that '/extras/config/screenshots/plugins' is being appended to root and the part-path to the theme directory is absent. – glvr Aug 13 '17 at 9:15
  • Sorry I'm not following you. You asked if you can use a variable to hold a path (you can) and I showed how to use it "inside" and "outside" of PHP. If you need something else please edit your question. – mayersdesign Aug 13 '17 at 9:35
  • Thanks. If, when creating the variable, I change '$url = bloginfo' (without quotes) to '$url = get_bloginfo' (without quotes), your code works ok. But when using '$url = bloginfo' (without quotes), the url/src is as-noted in an earlier comment minus the path to the template directory. So, acceptance applied. Thanks. ;-) – glvr Aug 13 '17 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.