• I have made several themes in WP, and no my way around the program pretty well. I have not worked with widgets, however. How much work is involved in making a theme “widget ready”?

    Thanks,

    – dz

Viewing 12 replies - 31 through 42 (of 42 total)
  • Thread Starter dwzemens

    (@dwzemens)

    That works, but it removes the markup and the title from ALL the text widgets, regardless if the title is empty or not. It doesn’t look like it should do that, but it does????

    im sure there must be a way.
    you need an if statement somewhere, saying if title is blank, dont register title, before title etc, and if it isnt blank, then put them in.
    unfortunately i cant work out how.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    My !empty statement should work, however, if you really want an if statement…

    <?php if (!empty($title)) echo $before_title . $title . $after_title; ?>

    You have to use empty() on strings. Because $title can be defined, but blank. empty() will return false if it’s a blank or non-existent string.

    The code going into the newest/latest/greatest version of widgets for this section is this:
    <?php print ( empty( $title ) ) ? '' : $before_title . $title . $after_title; ?>

    These two are functionally equivalent, really. More or less.

    i got an unexpected t variable error when i tried with the !empty, hence why i came up with the other way.
    it would definitely be improved functionality if the h2 tags were removed by default if they were left empty, IMHO.

    —-
    you edited before i could reply! hope all that helped dwzemens

    Thread Starter dwzemens

    (@dwzemens)

    Otto42,

    Your efforts are terrific, but I still have the HTML markup showing with a blank NBSP when I use your newest code. Weird.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Why do you have an &nbsp; character in the title? Make it blank, as in nothing at all. Not a space or an &nbsp;.

    Empty means empty. A space is not empty. ??

    Thread Starter dwzemens

    (@dwzemens)

    No, sorry, I did not explain myself. The actual output from the widget still shows the H2 tag with a NBSP inserted. I did not insert it.

    Like so:
    <h2 class="widgettitle">?</h2>

    The widget, or something, is writing the NBSP because I am not doing so in the widget interface.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Well, there has to be something there. It can’t pull the title out of nowhere.

    Try saving your text widget with spaces in the title and then changing it back to nothing afterwards.

    Thread Starter dwzemens

    (@dwzemens)

    No deal. Still marks up the HTML and shows the NBSP. Here is the code in my widgets.php:
    <?php echo $before_widget; ?>
    <?php //$title ? print($before_title . $title . $after_title) : null; ?>
    <?php if (!empty($title)) echo $before_title . $title . $after_title; ?>
    <div class="textwidget"><?php echo $text; ?></div>
    <?php echo $after_widget; ?>

    If I manually replace the $title variable with a blank string (in the code) then it does not show a NBSP in the markup, but it still outputs the H2 tags.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    If I manually replace the $title variable with a blank string (in the code) then it does not show a NBSP in the markup, but it still outputs the H2 tags

    I don’t even see how that’s possible.

    This, for example:

    <?php $title=""; ?>
    <?php if (!empty($title)) echo $before_title . $title . $after_title; ?>

    …should output nothing at all.

    Thread Starter dwzemens

    (@dwzemens)

    It’s weird, Otto. The code you have listed DOES output NOTHING. However, this code:

    <?php $title="THE TITLE"; ?>
    <?php if (!empty($title)) echo $before_title . $title . $after_title; ?>

    also outputs NOTHING. I can’t figure this out.

    dwzemens, i had similar problem… and was going to post if there was a solution, but found it by doing one little change.

    you dont need any additional code in functions.php, like you’ve and otto tried earlier, but what you can do is, go to widgets.php which is under wp-includes, and search for nbsp, you’ll find one of the php functions where it states when title is empty pring “&nbsp”, so just take that out of the quotes, save the file, and thats it!

    i feel like a genius. Cheers.

Viewing 12 replies - 31 through 42 (of 42 total)
  • The topic ‘Widget Ready — How much work?’ is closed to new replies.