Jump to content

Making images of certain classes not display in post snippet in Wordpress


Lucy

Recommended Posts

Could someone point me in the right direction with this? Not expecting anyone to write the code up for me, and I suspect it's not possible, but anyhow...

 

I'm making a Wordpress theme and want to enable my client to add an image to their posts that will act as a border. It will float to the left alongside the post.

 

The issue is that the image needs to be inserted at the very top of the post to make this work; therefore, it sits before the ' <--more--> ' tag and currently shows up in post snippets. The images are going to be made to fit the full size post, so obviously this isn't going to look good.

 

I have created a class for said images so I thought I might be able to use PHP to make it so images with that class will not show up in the short version of the post. Or is this more of a Javascript thing?

Link to comment
Share on other sites

You can use CSS to hide images. If they have a class name already you can select them by the class:

HTML:

<img src="..." alt="image" class="hidden-image">

CSS:

.hidden-image { display: none; }
Link to comment
Share on other sites

 

You can use CSS to hide images. If they have a class name already you can select them by the class:

 

I know, but I only want it to be hidden under some circumstances (when the post is not shown in full) - that's where I thought PHP might come in?

Link to comment
Share on other sites

If you know which condition is the one which makes them appear or not you can put the class on the image using PHP:

<img src="file.jpg" alt="image" <?php if($image_is_hidden) { echo 'class="hidden-image"'; } ?>>

Change $image_is_hidden for whatever the condition is which hides the image.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...