• Hi I’m a relative wordpress newbie. I’m trying to write my own plugin for purely for my own purposes. I’m trying to define a function which returns a block of html which can be called anywhere in a page…

    here goes my plugin:
    <?php
    /*
    Plugin Name: Blog Mela
    Version: 1.0
    Author: Saket Vaidya
    Author URI: https://www.vulturo.com
    Description: Bharateeya Blog Mela
    */

    function get_blogmela() {
    echo "<ul>
    <li>
    <a href="https://calamur.org/gargi/2005/06/18/bharateeya-blogmela-a-round-up/">Current Blog Mela</a></li>
    <li><a href="https://www.madhoo.com/archives/003267.php">Next Blog Mela</a></li>
    </ul>";
    }

    ?>

    But If I try to activate this plugin, It messes up my admin panel… and messes up all the pages where the “get_blogmela” function has been called.

    The issue is, the same thing works If I don’t supply links in the html blocks. For example.. this works:

    <?php
    /*
    Plugin Name: Blog Mela
    Version: 1.0
    Author: Saket Vaidya
    Author URI: https://www.vulturo.com
    Description: Bharateeya Blog Mela
    */

    function get_blogmela() {
    echo "<ul>
    <li>
    Plain Text</li>
    <li>More Plain Text</li>
    </ul>";
    }

    ?>

    Its funny, if the HTML block has hyperlinks, the plugin won’t work… it will work if it has plain text only.

    Can someone suggest a remedy?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter vulturo

    (@vulturo)

    Also…. The error is “unexpected T_string on some line in blogmela.php (the name of the plugin)” if I include the hyperlinks

    <?php
    /*
    Plugin Name: Blog Mela
    Version: 1.0
    Author: Saket Vaidya
    Author URI: https://www.vulturo.com
    Description: Bharateeya Blog Mela
    */

    function get_blogmela() {
    echo '<ul><li><a href="https://calamur.org/gargi/2005/06/18/bharateeya-blogmela-a-round-up/">Current Blog Mela</a></li>';
    echo '<li><a href="https://www.madhoo.com/archives/003267.php">Next Blog Mela</a></li>';
    echo '</ul>';
    }

    You can’t use the same kind of quotes inside a string which you used to open the string.

    These won’t work:
    echo "She said "Hi there!" to me";
    echo 'She said 'Hi there!' to me';

    These will work:
    echo "She saud 'Hi there!' to me";
    echo 'She said "Hi there!" to me';

    Note also that variable expansion will not take place inside single quotes.

    This won’t work:
    echo 'foo = $foo';

    This will work:
    echo "foo = $foo";

    Thread Starter vulturo

    (@vulturo)

    Thanks Skippy.

    It does work. But it also appends the following warning in my admin area:

    Warning: Cannot modify header information - headers already sent by (output started at /home/vulturo/public_html/wp-content/plugins/blogmela1.php:18) in /home/vulturo/public_html/wp-admin/admin.php on line 7

    Warning: Cannot modify header information - headers already sent by (output started at /home/vulturo/public_html/wp-content/plugins/blogmela1.php:18) in /home/vulturo/public_html/wp-admin/admin.php on line 8

    Warning: Cannot modify header information - headers already sent by (output started at /home/vulturo/public_html/wp-content/plugins/blogmela1.php:18) in /home/vulturo/public_html/wp-admin/admin.php on line 9

    Do you have any space between the beginning of the document and <?php ? Getting rid of that usually gets it

    Alternatively, try this:

    <?php
    /*
    Plugin Name: Blog Mela
    Version: 1.0
    Author: Saket Vaidya
    Author URI: https://www.vulturo.com
    Description: Bharateeya Blog Mela
    */

    function get_blogmela() {
    ?>

    <ul>
    <li>
    <a href="https://calamur.org/gargi/2005/06/18/bharateeya-blogmela-a-round-up/">Current Blog Mela</a></li>
    <li><a href="https://www.madhoo.com/archives/003267.php">Next Blog Mela</a></li>
    </ul>

    <?php
    }

    ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Plugin Writing Issues’ is closed to new replies.