• Hello guys,

    maybe the title is wrong, but I am not sure how to fix or search for this bug. Anyway, I am putting a screenshot here: http://i.imgur.com/2fDtbyT.png. I am echoing the content (get_the_content()) and if the description has a link inside, it totally messes up my code. What should I do?

    Thank you,
    G

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi georgecj, you have a few HTML errors in your code. Inside of your link, you have two incorrect closing </div> tags and an additional unclosed <div class="col-sm-3 col-xs-12">. This would definitely mess up your layout.

    Fix up those incorrect <div>‘s and that should fix your layout.

    You can validate your code here:
    https://validator.w3.org/#validate_by_input

    Thread Starter georgecj

    (@georgecj)

    Hello Moondrop,

    and thank you for your reply. No, that’s not the problem. The problem is the href inside that div. Because double quotes, it messes up the code. If I delete the link from WP inside content post, everything works fine.

    So I need a solution for double quotes or single, to let WP or PHP know to ignore them or something like that.

    Hope you understand now.

    Thank you!

    I am echoing the content (get_the_content())

    I am not sure why you are doing like this way, instead you can simply call

    
    echo get_the_content();
    
    Thread Starter georgecj

    (@georgecj)

    I am not sure you guys understand my real problem. Echoing the content -> echo get_the_content(), this is what I am already doing.

    The only problem is that the double quotes from href messes up the code, or I guess so.

    Hi georgecj, are you able to post your php code with the get_the_content() and the WYSIWYG code you are pulling from get_the_content()? The screenshot you provided only gives us part of the picture so it is difficult see what is causing the quote issue you mentioned.

    Thread Starter georgecj

    (@georgecj)

    Hello Moondrop,

    sorry I was away, I had no internet :D.

    Anyway, here is the code from php:

    <div class="descr">
    		<?php $content = get_the_content(); echo mb_strimwidth($content, 0, 140, '...');?>
    	</div>

    And here is the WYSIWYG code from post:
    There was an interesting article in <a href="http://www.forbes.com/sites/profdrwolfganggarlt/2016/09/12/chinese-tourists-wont-let-old-age-slow-them-down/#7cf8b1805495">Forbes</a> in September about the ‘silver wave’ in China’s outbound tourism. In the last 50 years, the life expectancy in China has improved from 43 years to 76, not only the older generation live long and are fitter, they have also got more money to spend.

    Together with the screenshot from first post, I think they are enough for you to understand what’s my problem.

    Thank you a lot !

    Hi georgecj, thanks for posting your full code!

    I can see now where the broken link is occurring. Your ‘mb_strimwidth’ function is trimming your link too early and causing it not to close correctly. You can see that in your imgur screenshot where you have “…” added inside of your link.

    If you remove the ‘mb_strimwidth’ it should fix your problem.

    However, I assume want the text to be retricted to a certain length. I recommend looking into using the ‘get_the_excerpt’ function and an excerpt plugin that allows html in excerpts. Those plugins will have code that identifies broken tags, from text trimming, and close them.

    Here’s a plugin I often use: https://en-ca.wordpress.org/plugins/advanced-excerpt/

    get_the_excerpt info: https://codex.wordpress.org/Function_Reference/get_the_excerpt

    • This reply was modified 9 years, 3 months ago by Moondrop. Reason: Typos
    Thread Starter georgecj

    (@georgecj)

    Hello Moondrop,

    now I saw my problem as well, did not think at first that should be the problem, but hey. I’ve used this snippet http://stackoverflow.com/a/10173268/2595273 and worked. So this solved my problem, thank to your idea.

    I really appreciate your help and thanks a lot,
    George

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘HTML entity problem’ is closed to new replies.