10 WordPress Code Snippets that Replace Plugin Functionality

Access, manage, update and backup all your WordPress sites from one powerful dashboard

Sign up - it's free!
post a comment


  1. Tom says:

    I'm using http://www.snip2code.com to collect snippet. Do you think that this kind of services can be useful?

  2. Nilesh says:

    I was looking for a email notification filter for contributors to notify them when a post get published and found your snippets. Thanks for sharing this.

  3. Dave says:

    Not sure if this the place ask this but here goes. I am new to wordpress and trying to change the login logo (#7). I am using wp3.5 I have found the functions.php and pasted the code in at the top of the page but I get an Fatal error: Call to undefined function add_action() in …/wp-includes/functions.php on line 8. No matter where I paste the code in functions.php I get the same message just with a different line #. Could you please advise a newbie what I am doing wrong.

    • Shea Bunge says:

      Hi, the problem is the you're pasting the code in the wrong place – it should go in the <code>functions.php</code> in your <em>theme's</em> folder, not in wp-includes. You can go to <em>Themes &gt; Editor</em> in your dashboard and select functions.php from the side menu. You may also be interested in <a href="http://wordpress.org/extend/plugins/code-snippets&quot; rel="nofollow">this plugin</a>

      • Dave says:

        Hi Shea, Thanks for your help and assistance it is now working a treat and I have learned so much more about WordPress. I have also downloaded and installed code snippets so hopefully no problems in the future. Once again many thanks.

  4. eRock says:

    Hi! Regarding #8, how would I write the code so the user can dismiss any warning messages by clicking a close button? Thanks!

    • Tom Ewer says:

      I'm afraid you've asked a question that surpasses my technical ability ;-)

      I'm sure you could get an answer over at the WordPress forums though.

    • bungeshea says:

      You could try the following code:

      /* Display a notice that can be dismissed */
      add_action('admin_notices', 'example_admin_notice');
      function example_admin_notice() {
      global $current_user ;
      $user_id = $current_user-&gt;ID;
      /* Check that the user hasn't already clicked to ignore the message */
      if ( ! get_user_meta($user_id, 'example_ignore_notice') ) {
      echo '&lt;div class=&quot;updated&quot;&gt;&lt;p&gt;';
      printf(__('This is an annoying nag message. Why do people make these? | &lt;a href=&quot;%1$s&quot;&gt;Hide Notice&lt;/a&gt;'), '?example_nag_ignore=0');
      echo &quot;&lt;/p&gt;&lt;/div&gt;&quot;;
      add_action('admin_init', 'example_nag_ignore');
      function example_nag_ignore() {
      global $current_user;
      $user_id = $current_user-&gt;ID;
      /* If user clicks to ignore the notice, add that to their user meta */
      if ( isset($_GET['example_nag_ignore']) &amp;&amp; '0' == $_GET['example_nag_ignore'] ) {
      add_user_meta($user_id, 'example_ignore_notice', 'true', true);

      Source: http://wptheming.com/2011/08/admin-notices-in-wordpress/

  5. #7 says "adjust the path and name of the image"

    I'm not exactly a beginning coder, but I can't see where the path and image name are in that snippet.

    • Tom Ewer says:

      Apologies Joel – WordPress mangles the code snippets every time I enter the visual editor (one of my real WordPress pet hates). The code should be displaying correctly now.

  6. Jacques says:

    - snippet 8 falls partially outside the 'code box'
    - not sure: do you need the favicon code? I think placing it in your root and/or theme folder, it will be picked up (might depend on browser, though)

    In general, thanks for this list – the less plugins, the merrier. In ManageWP, 'run code' provides this functionality, right? Can we just add the above snippets and run them?

    • bungeshea says:

      No, ManageWP's 'run code' functionality only executes the code once. You need to use the Code Snippets plugin (as mentioned above) to have them run every time someone visits your site.