Add span class to existing div class
-
Hello,
I have a basic question and hope I’ll find help here.
In the theme I am using I have a top-bar (left and right) containing contact data (phone number and address) including icons:
Sorry for the screenshots, I am developing on a local testmachine only.
Now I would like to add another icon and text after the address (envelope & email address). Using CSS (:after) only added the icon, but due to different font-families I wasn’t able to put the mail address behind it with default font type.
Next I was thinking about adding a class to the existing div class “site-top-bar-left”.Instead of using a child-theme I am using a plugin in which I can store my changes to CSS/PHP/JS files. Therefore I would need to be able to add that span class through my functions.php (as I think PHP is the way to choose, not javascript). But I am not getting it to work. Neither I do know where to add the action, nor how the function needs to look like. I tried several ways, but now I have to admit there still is a long road for me to go to get used to scripting. 🙁 But I am not giving up and that’s why I refuse to use a plugin.
Does any of you have hints for me guiding me in the right direction?Highly appreciated,
-BjörnThe page I need help with: [log in to see the link]
-
In order to change template content via a filter or action hook, the theme author would need to have anticipated this need and provided a hook base just for that purpose. You cannot change just anything you want through hooks, the original author needs to first provide the base for hooks.
Is there a particular reason why you don’t want to use a child theme? Child themes are the best way to customize templates when no hook base is provided.
While you cannot change a specific template element from a plugin if no hook base is provided, you can override the loading of the entire template file from a plugin with the “template_include” filter. As long as you return a full path to the replacement file, it can reside anywhere on the server.
Hi bcworkz,
thanks for your answer.
I was thinking about using a child theme, but wanted to find a better solution. Am going to take a closer look at the related template to search for the hook. If not successful overriding the template with “template_include” seems to be the way I’ll do it.
In the past I was able to implement all changes without being afraid of loss through updates just with that plugin (theme-customisation-master by James Koster). This way I learned a lot about the general structure of wordpress, but as you can see there is still so much to learn. 🙂Best regards,
-Björn
The topic ‘Add span class to existing div class’ is closed to new replies.