Category: Web Development

Posts regarding code or other web topics.

  • Home Networking Raspberry Pi “Pi-hole” Project Part 1

    The following posts will be on how to set up your own ‘Pi-hole’.

    What I wanted to do was set up my Pi to block ads, filter content, and serve as a secure VPN for when I’m connecting out in the real world where the bad hackers live.

    I started with a base of Jessie flavored Raspbian.

    Part 1 – block ads

    This part was easy.  Check this out:

    http://jacobsalmela.com/block-millions-ads-network-wide-with-a-raspberry-pi-hole-2-0/#install

    Not much to it.  Start with your base of Raspbian.  Make sure its up to date:

    sudo apt-get update

    sudo apt-get upgrade

    Then go get your pi-hole.

    curl -L install.pi-hole.net | bash

    Then configure your devices (or router) to use your Pi as its DNS server.

    I’m being lazy so you can check out the link above for links on how to do that.

    My router would not support it at the router level, so I configured devices individually.  You will need to know your Pi’s ip address.  It should probably be static.  A later post will cover how I handle static ip’s for all my devices.

    Now when I browse the web I get empty space where once ads stood.

    Next time I’ll go over content filtering.  Until then, stay frosty.


  • WordPress Web Application Development Review

    WordPress Web Application Development Review

    I recently read WordPress Web Application Development by Rakhitha Nimesh Ratnayake.  You can get your copy here:

    http://bit.ly/1e3ioxG

    As the title implies it covers using WordPress as your application framework.  I highly recommend this book even if you are not building a web app.  The author does a great job of breaking down complex development techniques that are useful regardless of how you plan to use WordPress.  I found learning about how to use built in functions the most helpful.  Did not realize how much WordPress provides for you as far as development goes.


  • Return vs Echo

    I recently made a mistake that I wanted to share. It might save you a headache.

    When making a short code make sure to return a value and not just echo it out.

    The echo will display content, but it’s placement will be off, which is what gave me my headache.

    Instead, put your echo’s in a string then return it.

    [code]
    //incorrect
    function foobar_func( $atts ){
    echo "foo and bar";
    }
    add_shortcode( ‘foobar’, ‘foobar_func’ );
    //correct
    function foobar_func( $atts ){
    return "foo and bar";
    }
    add_shortcode( ‘foobar’, ‘foobar_func’ );
    [/code]


  • CSS Font Shorthand

    I’m always forgetting the CSS syntax for font in shorthand format. Here is a great reference:

    Font Shorthand


  • Add Custom Help Section

    You create a fancy new site for a client which is awesome.  However, the client is constantly calling you with ‘how-to’ questions.

    One way to solve this is to create a custom help section tailored to your design and functionality.

    Step 1

    Head out to http://www.iconarchive.com/ and pick up a 16×16 png icon to use as your help icon.  I picked up a question mark.

    Step 2

    Create a folder to hold the help plugin.  Add your help icon to it.

    Step 3

    Create the ‘help.php’ file.  Add the following code:

    [code]
    <?php
    /*
    Plugin Name: Custom Help Section
    Plugin URI: http://www.mattchristensen.net
    Description: Creates iframe in the admin to add your own ‘Help’ section
    Version: 1.0
    Author: Matt Christensen
    Author URI: http://www.mattchristensen.net
    License: GPLv2
    */

    add_action( ‘admin_menu’, ‘christensen_help_menu’ );

    function christensen_help_menu() {
    add_menu_page(‘Help’, ‘Help’, ‘manage_options’, ‘christensen_help_menu_section’, ‘christensen_help_display’, plugins_url(‘Help-icon.png’, __FILE__));
    }

    function christensen_help_display(){
    echo ‘<iframe src="http://www.example.com"></iframe>’;
    }

    ?>
    [/code]
    Change the names/details to match your needs.

    Step 4

    Create the html help page that the plugin points to from step 3.

    Step 5

    Upload to your plugin directory and activate.

    Then you can update the html page with new help sections without having to edit the plugin or the client’s site.
    This is ‘mark 1’. Will update with the ability to add the iframe url from the admin so you don’t have to make a custom plugin for each site you create.


  • Disable edit

    Want to keep a client from editing your plugins and themes from the admin?
    Add this to the functions file.

    [code]
    define( ‘DISALLOW_FILE_EDIT’, true );
    [/code]