Filters....I think... (7 posts)

  1. NovaSev
    Posted 2 years ago #

    So I'm using the wp_login_form(). All of it's working swell but...

    Here's my issue - I want to change the class that is automatically populated with it's submit button. I've done so by just changing the class in the wp-includes/general-template.php but I'm sure that gets written over again once I have to update wordpress. Can I do a filter for this? Is there a good link that you can provide that will show me how to create a filter for this and possibly other things as well?

    I'm a bit new to php so this may be really simple .... thanks for the help.

  2. bcworkz
    Posted 2 years ago #

    If you call wp_login_form() with the argument 'echo'=>false, the form HTML is returned instead of echoed directly. Capture the returned HTML in a variable and use str_replace() to replace the default class with what you want, then echo the result.

  3. NovaSev
    Posted 2 years ago #

    I'll see what i can do with that on my own - thank you for your reply :)

  4. NovaSev
    Posted 2 years ago #

    Can you walk me through it a bit more bcworkz? I'm horrid when it comes to PHP at the moment and I've searched for this for a while now with no luck.

  5. bcworkz
    Posted 2 years ago #

    I'm not sure what your current code looks like, so you'll need to fill in the gaps. Something roughly like this:

    $form = wp_login_form( array(
    echo str_replace('button-primary', 'novasev_class', $form );
  6. NovaSev
    Posted 2 years ago #

    Okay, wouldn't that replace the entire login form with this class though? I was thinking it would be something like this:

    // Add selector to loginout php code
    add_filter('loginout', 'loginout_selector');
    function loginout_selector($text) {
    		$selector = 'class="logging" ';
    		$text = str_replace('<a ', '<a '.$selector, $text);
    		return $text;

    So that way, I'm just picking out the single element that I want to add a different class to (the button only) and the rest is left alone. I just don't know how to find the stuff that I actually need far as the names for the button at this point.

  7. bcworkz
    Posted 2 years ago #

    I'm pretty sure the only place "button-primary" appears in the login form is the class for the submit button alone. Check the HTML source of the login form output to be sure. That will show you what you really need to search for for proper replacement. One way or another, there's a way to achieve what your need by suppressing the echo.

    'loginout' will not help with the login form itself, that filter is for the simple login or logout link, not the form. The login form function does not have a similar filter because one can suppress the echo and do what I am suggesting. (There are filters, but they do not give access to the form HTML)

Topic Closed

This topic has been closed to new replies.

About this Topic