content: attr () not working in CSS

  • Unknown's avatar

    Hi! I have another question about my site.

    I want to define a variable (in this case an authors name I can duplicate on the site ultimately in a widget I’m hoping) this way:

    In the HTML:
    <var>Authors name</var>
    In the CSS:

    article::before {
    	content: attr(var);
    }

    I know the article::before and content bits are working, because if I erase attr(var) and type “hello” everything works fine. Is there a way to do this? Var isn’t ideal but its the only workaround I can think of with the limited HTML codes available. I originally tried
    <p id="xyz" data-source="Authors name goes here"></p> but that was stripped.

    The blog I need help with is: (visible only to logged in users)

  • Unfortunately, I don’t think it’s possible to do the sort of dyanamic display you’re trying to do with CSS alone.

    You could do:

    article::before {
    	content: "Author's name";
    }

    But that requires putting the name directly into the CSS.

    Can you explain what you’re trying to do a little more? I might be able to think of a workaround.

  • Unknown's avatar

    Hi Kathryn, thanks for responding. I need a better way to display my authors.

    My site is a forum, with non-wordpress guest posters. The posts will be 100% from outside authors, so I essentially need to add them to the meta (not do-able on WordPress), or find a way to define them as some sort of attribute, so I am able to group them together. For example, at the moment I won’t be able to say “See more posts from this author” and link to all their posts on my site.

    Any help is greatly appreciated.

  • What about adding a tag on each post by that author?

    That way you could add a link like:

    See all posts by <a href="https://forcedmigrationforum.com/tag/jill-smith/">Jill Smith</a>

    Or you could do the same with categories, if you prefer.

  • Unknown's avatar

    Hi Kathryn,

    That could work, and I’ve thought of that, but the problem there is that Google isn’t recognizing the author of the post. I would like the ability to add a meta tag, and would suggest that WordPress allow that in the future.

    Thank you

  • With the Premium plan — which you have — it’s possible to set a meta description for individual posts and pages, as well as the front page:
    https://en.support.wordpress.com/seo-tools/

    If you let me know what kind of other meta tag you’re referring to, I can either see if it’s already possible or suggest it to our developers as a future enhancement.

  • Unknown's avatar

    Hi Kathryn,
    If I’m not mistaken, I need to upgrade further to the business plan to access that feature.

    In terms of a meta tag, I’d just like the option to choose who is authoring my post, without them having to set up a wordpress account and submit it themselves. I.e., the ability to say that I am not the author, someone else is the author, and have them displayed where the current author meta tag shows up.

  • If I’m not mistaken, I need to upgrade further to the business plan to access that feature.

    Ah you’re right, my apologies.

    In terms of a meta tag, I’d just like the option to choose who is authoring my post, without them having to set up a wordpress account and submit it themselves. I.e., the ability to say that I am not the author, someone else is the author, and have them displayed where the current author meta tag shows up.

    I see, thanks for explaining. Core WordPress behaviour is that a post can only be authored by a user in the system, so I don’t think this is something we’re likely to change as it’s not a common request and part of the underlying core WordPress software. That said, you could always set up “dummy” user accounts for your authors, even if they don’t ever log in themselves. You can then set them as the author of their respective posts. A Gmail would be handy for this, as you can do something like myemail+donna at gmail.com, myemail+jim at gmail.com, but all the addresses would direct to your account. (Everything after the + is ignored by Gmail, but they’re treated as unique addressees in WordPress.com) Perhaps this could be your workaround.

  • The topic ‘content: attr () not working in CSS’ is closed to new replies.