WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. redheadkelly
    Member
    Posted 1 year 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?

    Thanks.

    http://wordpress.org/extend/plugins/php-code-widget/

  2. Samuel Wood (Otto)
    Tech Ninja
    Plugin Author

    Posted 1 year 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
    Member
    Posted 1 year 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.

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

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

    Nothing.

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

  4. redheadkelly
    Member
    Posted 1 year ago #

    OK... got a reply from EasyBib.

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

    Thanks!!!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.