• Ken

    (@synsanken)


    Is there a post text class that sets the font color for my posts?

    I have one post that is going to be unique. It will be the only post like this on my blog, so I’m just adding a span around the text, and I need the border color to be the same as my text color:

    1.33<span style="border-top: 1px solid #d0d0d0;">3</span>, 4.7234<span style="border-top: 1px solid #d0d0d0;">234</span>

    It works, but if I ever change my theme, it won’t work anymore unless I edit that post. ChatGPT said I can use: entry-content, but I’m not sure if assigning that class to a span will mess anything up.

    I just want those borders to be the same color as my font color.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    Any specific classes that manage styling are theme specific. Span style attributes as you’ve done will persist regardless of your chosen theme. Style attributes are difficult to override through CSS precedence. This can be a good thing or a bad thing. IMO it’s usually a bad thing. If you have 50 bordered text boxes on your site and you decide you want the border to be green instead of gray, editing 50 different style attributes will be a huge tedious PITA.

    It’s better IMO to give the span a custom class, for example ken-hilite-box. Then enqueue all appropriate CSS related to your custom classes from your own custom plugin. The you can change themes as you wish while your plugin’s specific styling will be applied regardless. Then if you later decide you want a green border instead of gray, you only need to change the CSS in one place in your plugin and it would effect all 50 or more instances of your class.

    Thread Starter Ken

    (@synsanken)

    What I’m planning on doing is just assigning the span to a class and adding that class in additional CSS box. If I needed to change the border later, I can just edit the additional CSS in one place.

    But I don’t know if the code I type in additional CSS box will get deleted if I change the theme.

    Moderator bcworkz

    (@bcworkz)

    It’s not actually deleted, but it’s tied to the theme. Additional CSS of another theme will be unique to that theme. But if you were to revert back to your initial theme, your additional CSS will still be there. What actually happens with additional CSS is it’s saved in the option table under the theme’s name. Changing themes does not remove it, but the new theme has its own option item for additional CSS.

    You of course could copy your additional CSS from one theme to another, but if you want your CSS to persist between various themes without needing to copy/paste, you should apply your custom CSS via your own plugin. Developing a bespoke plugin might sound daunting but it doesn’t need to be all that difficult. It will involve a small amount of PHP code. Even if you don’t know PHP, you can likely muddle through and get something working if someone points you in the right direction ??

    Thread Starter Ken

    (@synsanken)

    I’m going to try it, if I can find tutorials on how to do it. I wanted to try creating my own plugin and theme, but it looked like it would be too complicated. There are so many files in WordPress.

    I have a lot of programming experience, but not with PHP. It would be cool to be able to modify my website a little.

    Moderator bcworkz

    (@bcworkz)

    Making a plugin is fairly simple, it does not require any real coding skill, only minimal server file management skill, either via FTP or your hosting file manager.

    The plugin will not do anything unless you add some PHP, but it’ll exist as a plugin all the same. You can pick up some PHP knowledge as you go. You really only need to learn enough to accomplish the task at hand. The more you modify your site, the more you learn ??

    To apply CSS via a plugin, first create a .css file containing all of your custom CSS. Then in you plugin’s main .php file that contains the comment header, call add_action() to add a callback function to the “wp_enqueue_scripts” action hook. You will then declare the callback function which will call wp_enqueue_style() to enqueue your .css file. There are a number of user contributed examples near the bottom of the linked page to help you get started. This enqueue process is how WP places link references on a page which loads external CSS and JS files.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Access Post Text Class?’ is closed to new replies.