PHP Code Widget
[resolved] Can't call site title that includes ampersand (4 posts)

  1. redheadkelly
    Posted 3 years ago #

    I had a line of code in the widget to grab the site title:

    "site":"<?php bloginfo('name'); ?>",

    this worked great until I changed the site title to something that contains an ampersand, then the widget quit working.

    Any suggestions?



  2. Samuel Wood (Otto)
    WordPress.org Tech Dude
    Plugin Author

    Posted 3 years ago #

    Presumably you're using that in some kind of javascript code or something along those lines?

    HTML is not allowed to contain bare ampersands. They need to be changed to & amp; to be interpreted properly. Basically, run it through htmlspecialchars() before outputting it.

    <?php echo htmlspecialchars(get_bloginfo('name')); ?>

  3. redheadkelly
    Posted 3 years ago #

    Thanks for the reply.

    Oh yes. Sorry. That is what I'm doing. php within the javascript within the php widget. I'm using EasyBib's widget... http://www.easybib.com/developer/easybib-cite-widget

    I had to change it a bit to get it to grab the info right from WordPress. It all worked great together until I added the ampersand to the site title.

    I tried your suggestion & changed the line to
    "site":"<?php echo htmlspecialchars(get_bloginfo('name')); ?>",
    but it still doesn't work.

    "site":"<?php htmlspecialchars(bloginfo('name')); ?>",

    Then I just took the simplest route...
    "site":"Out of the Family Tree & into the Fry-ing Pan",


    As soon as I remove the & from the line, it works great.

  4. redheadkelly
    Posted 3 years ago #

    OK... got a reply from EasyBib.

    This worked:
    "site":escape("<?php bloginfo('name'); ?>"),


Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic


No tags yet.