0

I want to create a plugin that adds specific class to all a tags.

  • 3
    This question doesn't really make sense. "Widgets" are distinct items from posts. They don't really interact much, and certainly not in that way. Asking for a widget that alters post content is like asking for a bicycle that changes the color of the seats in your car. Please clarify what you are trying to do and why. – s_ha_dum Mar 2 '14 at 14:17
  • I think you are not looking for a widget but a custom function or --if you want to 'install' your functionality-- a plugin – Christoph Mar 2 '14 at 16:27
  • Actually the word Widgets confused everybody, I ment plugin! – wordpressguest Mar 2 '14 at 18:38
  • WordPress doesn't provide any filter (or function) to add classes to heading tags in post content. Try filtering the_content with str_replace. – Abhik Mar 2 '14 at 19:32
0

As s_ha_dum said, Widgets are not meant to be used like this.

If you want to change the behavior of all your h3 tags inside your posts, Wordpress has already article with "post" or "type-post" classes so you should modify your css like this :

.post h3 { *** }

If you want your change to affect only a specific type of posts :

  1. Add a specific class mySpecificPostClass around the posts you want to change
  2. Modify your css style and use something like

.mySpecificPostClass h3 { *** }

More detail here.

Edit 1 :

if you want a plugin to do it, you will find a first answer here: Where is the right place to register/enqueue scripts & styles.

For a tutorial on plugin creation, look here: https://codex.wordpress.org/Writing_a_Plugin

In the case of a plugin, as you want to change to behavior of the h3 tags of posts, you don't have to add specific class :

  1. Create a style to overload the default style only for h3 tags inside "post" class : .post h3 { *your style* }

  2. Add your style in the queue with a plugin

Then your new style will be added to the default style without any change in the theme.

You will want to use a specific class only if you are gonna use it someplace else. If you want to use it only for all posts as your question suggest, no need for that.

Edit 2 :

You can overload the function post_class() ( http://codex.wordpress.org/Function_Reference/post_class) using a filter : add_filter('post_class','my_func')

Your function my_func will then have to return the regular classes plus your specific one.

  • 1
    @wordpressguest Would you mind reading what Widgets actually are? – kaiser Mar 2 '14 at 16:07
  • Okay, so how can i achieve this, without manually editing the css file? – wordpressguest Mar 2 '14 at 18:01
  • @wordpressguest Could you edit your question and add details, constraints and final goal you want to reach ? It's definitively doesn't sound like a widget problem. Have you looked at what plugins does ? Are the posts you want to modify regular posts or special ones ? – Olivier Mar 2 '14 at 18:09
  • Then you indeed want to use a plugin and you will find the answer here : wordpress.stackexchange.com/questions/21561/… – Olivier Mar 2 '14 at 18:54
  • You don't need to add class if you want to change all the h3 tags from article. You just add to make sure the css style you enqueue overload the default one. Updating my answer :) – Olivier Mar 2 '14 at 19:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.