admin管理员组

文章数量:1122832

How can I hide just the author from the post meta in search results, while keeping the date and categories?

I know I can use something like:

.post-meta .author { display: none; }

to hide the author name, but that still leaves me with "by" and a vertical separator before the date.

"by" and the separator are not linked to any class, so how can I target and hide them, without hiding the entire .post-meta?

I'm using Divi, if that matters, and here is the full markup of the meta section:

<p class="post-meta">by <span class="author vcard"><a href="[link to author page]" title="Posts by [me]" rel="author">[my name]</a></span> | <span class="published">Jun 3, 2019</span></p>

How can I hide just the author from the post meta in search results, while keeping the date and categories?

I know I can use something like:

.post-meta .author { display: none; }

to hide the author name, but that still leaves me with "by" and a vertical separator before the date.

"by" and the separator are not linked to any class, so how can I target and hide them, without hiding the entire .post-meta?

I'm using Divi, if that matters, and here is the full markup of the meta section:

<p class="post-meta">by <span class="author vcard"><a href="[link to author page]" title="Posts by [me]" rel="author">[my name]</a></span> | <span class="published">Jun 3, 2019</span></p>
Share Improve this question edited Sep 6, 2019 at 20:04 RiddleMeThis 3,7878 gold badges21 silver badges30 bronze badges asked Sep 6, 2019 at 19:00 ManlyManly 1435 bronze badges 2
  • Your best bet would be to edit the template that is generating the post meta, then you could display exactly what you want. – RiddleMeThis Commented Sep 6, 2019 at 19:59
  • The structure of the HTML means that you can't do this with CSS. You'll need to change the template. – Jacob Peattie Commented Sep 11, 2019 at 9:51
Add a comment  | 

1 Answer 1

Reset to default 0

As stated in my comment the best solution would be to create a child theme and edit the file generating the post meta. This would give you full control of what is being generated and you won't have to worry about hiding unwanted content via CSS.

However, you could hide the text nodes and show the elements you want by doing something like this...

    .post-meta {
        visibility:collapse;
    }

    .published {
        visibility:visible;
    }

Note: The above hidden items will still keep their space in the DOM, so you could add float:left to .published to break the flow.

本文标签: phpHide author from search results metastill display date and categories