I am editing the sidebar widgets and have added one for users who are not logged in or registered. the widget requests that users register or login and I am wanting to add a random reason (quote) as to why they should join which will change after every reload of the page.

I have chosen to use the "text" in the site which does not seem to load any of the JavaScript codes that I enter. It obviously does not read them.

does anyone know of how I can do this?

If i'm using the wrong widget type then which one will read and display the JavaScript code?

or is there a none JavaScript way of doing this?

thank you.


  • sorted this by installing "HTML JAVASCRIPT ADDER". Jun 9, 2013 at 13:38

2 Answers 2


You say that you are...

... wanting to add a random reason (quote) as to why they should join which will change after every reload of the page

And you seem to trying to do this by placing Javascript in a text widget. I assume that is what you mean by the '"text" in the site'.

Based on that description, you don't need Javascript. You need a new sidebar widget.

class Quote_Login extends WP_Widget {
  /*constructs etc*/
  function __construct($id = 'quologin', $descr = 'Quote Login', $opts = array()) {
    $widget_opts = array();

  function widget() { 
    $ar = array(
      '“Nothing is as easy as it looks.”',
      '“Everything takes longer than you think.”',
      '“Anything that can go wrong will go wrong.”',
      '“If there is a possibility of several things going wrong, the one that will cause the most damage will be the one to go wrong.”',
      '“If there is a worse time for something to go wrong, it will happen then.”',
      '“If anything simply cannot go wrong, it will anyway.”',
      '“If you perceive that there are four possible ways in which a procedure can go wrong, and circumvent these, then a fifth way, unprepared for, will promptly develop.”',
      '“Left to themselves, things tend to go from bad to worse.”',
      '“If everything seems to be going well, you have obviously overlooked something.”',
      '“Nature always sides with the hidden flaw.”',
      '“Mother nature is a bitch.”',
      '“It is impossible to make anything foolproof because fools are so ingenious.”',
      '“Whenever you set out to do something, something else must be done first.”',
      '“Every solution breeds new problems.”',
      '“Trust everybody … then cut the cards.”',
      '“Two wrongs are only the beginning.”',
      '“If at first you don’t succeed, destroy all evidence that you tried.”',
      '“To succeed in politics, it is often necessary to rise above your principles.”',
      '“Exceptions prove the rule … and wreck the budget.”',
      '“Success always occurs in private, and failure in full view.”',
    $quote = $ar[array_rand($ar,1)]; ?>
    <p><b>It looks like you haven’t logged in or have not yet registered.<br>
To receive the most accurate results and member benefits, login below or click register to become a member.</b></p>
      <form action="wp-login.php" method="LINK">
        <b><br><input type="submit" value="LOGIN"><br></b>
    <b><p>Why Become A Member?</p>
    <form name="random">
      <input type="text" value="" size="78" name="random" />
      // here is your quote
      // the curly quotes you apparently want won't work in the form input
      // but I don't know why you are shoving this into an input anyway
      echo $quote; ?>
      <form action="wp-register.php" method="LINK"><br>
        <input type="submit" value="REGISTER"><br>
    </b><p><b>XCLO</b></p> <?php
add_action('widgets_init', function() { register_widget("Quote_Login"); } );

You only need Javascript if you need the quote to change periodically without having the page reload.

I did not correct your basic markup (much) but a few things strike me as odd, such as the use of forms to create what are essentially links and the use of deprecated in HTML4 and unsupported in HTML5 elements like <center>

  • This is good. This also worked for me but if i'm being honest installing the HTML JAVASCRIPT ADDER plugin makes provides the same affect. thanks. Jun 10, 2013 at 16:06
  • It is your site and of course you can do what you want with it but if you only need the results to change on page load and not periodically without having the page reloading, the Javascript solution is almost certainly slower and more prone to failure. Your solution might work but I question whether it is the best solution.
    – s_ha_dum
    Jun 10, 2013 at 16:12

sorted this by installing the "HTML JAVASCRIPT ADDER" plugin.


  • 1
    How about proper lower- and uppercase characters, a link to the source and an explanation why this plugin solved your problem?
    – kaiser
    Jun 10, 2013 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.