1

I'm using WordPress 4.1.2

I have this bit of php that displays the list of tags to the left of a small image:

<p align="right"><?php
the_tags( '&#160; ', ' • ', '<a href="https://www.lawlessfrench.com/faq/lessons-by-level/"><img src="https://www.lawlessfrench.com/graphics/icon-files.png" alt="Lawless French Files" width="20" height="30" align="right" hspace="10" border="0"></a>' );
?></p>

I want to replace the img with a sprite:

<div id="icon-files" style="float:right; height:30px; width:20px margin:10px" alt="Lawless French Files"></div>

So this is the code I'm using:

<?php the_tags( '&#160; ', ' • ', '<a href="https://www.lawlessfrench.com/faq/lessons-by-level/"><div id="icon-files" style="float:right; height:30px; width:20px margin:10px" alt="Lawless French Files"></div></a>' ); ?>

But it doesn't work - the image goes down to the next line instead of staying to the right of the tags.

Is there some trick to using div tags inside of php? You can see it in action at https://www.lawlessfrench.com

lkl
  • 263
  • 3
  • 15
  • How is your code for the replacement of img by div ? – user2267379 Apr 23 '15 at 21:25
  • I'm just putting the div code where the img code is: `
    ' ); ?>`
    – lkl Apr 23 '15 at 21:27
  • Your code source is not good ? (with " view-source:" before url) – user2267379 Apr 23 '15 at 21:27
  • I don't understand your question. – lkl Apr 23 '15 at 21:29
  • Try in your browser "view-source:" + your domain name. And check the code source. It is not good ? What is the exact difference between what you have and what you want ? – user2267379 Apr 23 '15 at 21:31
  • I've already done that - as I explained, the code is somehow different in view source than what I actually used on the site. I have `
    ` and it's being changed to `
    `. I can see that in the source code, but it doesn't help me figure out why and how that change is occurring.
    – lkl Apr 23 '15 at 21:34
  • You should say that you are using wordpress, and use wordpress tag. Version may help too. – Choma Apr 23 '15 at 21:35
  • Try this in your browser `view-source:https://www.lawlessfrench.com/` I see : `
    ` in the source code. `
    ` . This is not what you want ?
    – user2267379 Apr 23 '15 at 21:35
  • Using an `id` inside a loop will generate incorrect html. You shouldn't repeat an id on the same page. Try using a `class` instead. – Choma Apr 23 '15 at 21:41
  • Yes, that is what I typed and that is what I see when I view source that way. However, it's not working properly. If you look at the live site, the tags at the end of each post are right-aligned, and the icon follows on the next line. But they are supposed to be side by side. – lkl Apr 23 '15 at 21:42
  • Please, post the updated code for `the_tag()` that you are using. I mean, the call with the new params you are passing – Choma Apr 23 '15 at 21:48
  • Added to my original question @Choma – lkl Apr 23 '15 at 21:53
  • 1
    Did you try using a `span` tag, instead of a `div`? – Choma Apr 23 '15 at 21:55
  • You can mark my answer good by checking the green check. – user2267379 Apr 23 '15 at 21:59
  • Choma's suggestion of `span` rather than `div` is what worked. – lkl Apr 23 '15 at 22:00
  • I'm glad it worked, anyway... avoid using the same id more than once, instead use classes! :) – Choma Apr 23 '15 at 22:03

2 Answers2

1

Copy paste this in your url :

view-source:https://www.lawlessfrench.com/

The code source is good :

 <a href ...><div ...></div></a>

When you remove <p> tag around that works.

<div> tag in a <p> tag doesn't work correctly.

View here :

Why <p> tag can't contain <div> tag inside it?

This is consistent with http://www.w3.org/TR/html401/struct/text.html#h-9.3.1, >which says that the P element "cannot contain block-level elements (including P >itself)."

and :

the opening <div> tag will automatically close the <p> element.

Just remove <p> tag.

Or use <span> tag instead of <div> tag.

Community
  • 1
  • 1
user2267379
  • 1,067
  • 2
  • 10
  • 20
0

Don't use "p" for your tag P will break into new line,insted use div.

ermias amb
  • 11
  • 3