• Resolved HackYaaaaa

    (@hackyaaaaa)


    I need to add a class to the below div.

    <h3 id="reply-title">

    This div is located in comment-template.php. (line 1554)

    I try to never touch the core file but I can’t think of a way to add a class to this div.

    Can anyone help me?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter HackYaaaaa

    (@hackyaaaaa)

    answering my own question:

    used jQuery to add a class to it on .load.

    I am still curious though how something like this can be done in php. I am sure there is a way to do it; it’s just that I am lot more familiar with jQuery.

    Any php programmer here who maybe able to provide a clue or should I head over to stackoverflow? ??

    Moderator bcworkz

    (@bcworkz)

    You can wrap the entire form in a div of whatever class quite easily by hooking ‘comment_form_before’ and ‘comment_form_after’ actions. If the added class must be specifically added to the H3 element, the clean PHP approach is rather extreme, jQuery is the way to go in that case.

    By all means try other resources, that is the beauty of the Internet ??

    Thread Starter HackYaaaaa

    (@hackyaaaaa)

    Someone at stackoverflow suggested that perhaps I should talk to WordPress organization about this.

    <h3 id=”reply-title”>

    This h3 tag resides in core file and there isn’t a way to add a class to it in pure php. As someone @stackoverflow pointed out, and I concur, once the page loads, php has no way of altering the already loaded html.

    If there is, I wouldn’t know how to go about it. What I ended up doing was by hooking the comment_form in comments.php, I’ve inserted a sub element (span tag) below/inside the <h3> tag.

    This does the job & this does not involve jQuery but I am not happy with it as this adds extra element to the html (extra span tag), making my code looking ugly. ??

    I really feel like some guru programmer needs to sort this out for WP community. (I’ve encountered other developers struggling with this same subject.)

    Either you roll your dice with jQuery hoping no one is visiting your site with javascript disabled or you end up with ugly html.

    Neither is ideal.

    Moderator bcworkz

    (@bcworkz)

    “…making my code looking ugly.”
    ?? Only coders understand why this is a problem… or care. But some are of the opinion that there is a lot of ugliness in WP as it is. I doubt WP will ever have enough hooks to satisfy everyone, I guess they have to draw the line somewhere, but hardcoding unfiltered HTML often frustrates me into resorting to javascript ??

    Yes, it is impossible for PHP to influence HTML content once it is sent to the browser, except by injecting some javascript to run, which is unreliable at best.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘adding a class to a div w/o touching the core file’ is closed to new replies.