• The situation:
    I’m getting a list of posts, like so…
    $myposts = get_posts( $args );

    and putting each post found into a new list item with structure…
    <li><a><div></div><span></span></a></li>

    To that div tag, I’m adding a style…
    <div style="background-image: url('/fixed-root/plus-variable-based-on-post-title.png');"></div>

    The raw post title is written into the span…
    <span><?php the_title(); ?></span>

    The problem:
    The background image url is having a %C2%A0 added into it which breaks it.
    Turning off dewidowing makes the background-image-url work, but then display in other areas is not as nice.

    I don’t think this is intended behaviour, so if there’s a workaround anybody could tell me about?
    Or if it’s not been seen before and could be fixed, that’d be brilliant!

    This is how I form the background-image url:
    (Spaces added in to & nbsp;, & #160;, & #xA0;, and & amp; for display)

    <?php
    $theTitle = get_the_title();
    $theTitle = str_replace("& nbsp;?", "", $theTitle);
    $theTitle = str_replace("& #160;?", "", $theTitle);
    $theTitle = str_replace("& #xA0;", "", $theTitle);
    $theTitle = str_replace("& #x00A0;", "", $theTitle);
    $theTitle = str_replace("& amp;", "", $theTitle);
    $theTitle = str_replace("%C2%A0", "", $theTitle);
    $theTitle = str_replace("=C2=A0", "", $theTitle);
    $theTitle = str_replace(" ", "", $theTitle);
    $thumbUrl = "/images/speakers/".$theTitle.".png";
    ?>
    <div style="background-image: url(<?php echo($thumbUrl); ?>);" class="speaker-thumb circle"></div>

    Any help and suggestions greatly appreciated!

Viewing 1 replies (of 1 total)
  • Thread Starter mkv2

    (@mkv2)

    Right, I’ve got a workaround which works for me and lets me keep wp-typography switched on. Posting here in case someone finds it useful…

    Here’s what I’m now using:

    <?php
    $theTitle = get_the_title();
    $theTitle = strip_tags($theTitle);
    $theTitle = urlencode($theTitle);
    $theTitle = str_replace("%C2%A0","+",$theTitle);
    $theTitle = urldecode($theTitle);
    $theTitle = str_replace(" ","",$theTitle);
    $theTitle = str_replace("&","",$theTitle);
    $thumbUrl = "/images/speakers/".$theTitle.".png";
    ?>

    The result of which gets me the plain text of the title without spaces or ampersands. Phew!

    The call to strip_tags() is in there specifically to get rid of the span class=”caps” which shows up on certain titles.

    Two ways I can think of to do this better (but haven’t been able to actually do yet) would be:
    1. Replacing the %C2%A0 character(s?) prior to urlencoding it.
    2. Reading the un-“wp-typography” affected post title directly.

    If anybody knows of an easier way, I’d love to here about it!

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: wp-Typography] Dewidow function affecting inline styling’ is closed to new replies.