Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

Writing Wordpress Modules

  • 21-05-2015 1:35pm
    #1
    Registered Users Posts: 1,987 ✭✭✭


    I'm looking for a good tutorial/examples on writing wordpress modules with custom PHP functionality, can anyone recommend any?
    Tagged:


Comments

  • Registered Users Posts: 1,530 ✭✭✭jooksavage


    Ziycon wrote: »
    I'm looking for a good tutorial/examples on writing wordpress modules with custom functionality, can anyone recommend any?

    This one got me started writing plugins
    http://www.elegantthemes.com/blog/tips-tricks/how-to-create-a-wordpress-plugin


  • Registered Users Posts: 1,530 ✭✭✭jooksavage


    Ziycon wrote: »
    I'm looking for a good tutorial/examples on writing wordpress modules with custom functionality, can anyone recommend any?

    Also if you want to add custom fields to all/specific site pages, the Advanced Custom Fields plugin will do almost everything you could want.


  • Registered Users Posts: 1,987 ✭✭✭Ziycon


    It's to have a custom feature that will exist on one page that has some complex logic in it but only ever exists on the one page.


  • Registered Users Posts: 1,530 ✭✭✭jooksavage


    Ziycon wrote: »
    It's to have a custom feature that will exist on one page that has some complex logic in it but only ever exists on the one page.

    Is it going to have an admistrative screen in the Wordpress CMS, ie. Is it something that will be updated by logged-in users?


  • Registered Users Posts: 1,987 ✭✭✭Ziycon


    jooksavage wrote: »
    Is it going to have an admistrative screen in the Wordpress CMS, ie. Is it something that will be updated by logged-in users?

    No, just pure functionality on the public facing page, no need for a backend admin section.


  • Advertisement
  • Registered Users Posts: 1,530 ✭✭✭jooksavage


    Probably don't need that plugin tutorial I posted earlier so.

    It might be just a case of a building something into your WordPress theme. Find the .php file you need to update (depends on the theme, could be header.php, content.php, content-page.php, etc.), locate where you want the functionality to appear and paste in the code inside conditional statement like if page(page id here){do stuff}


  • Registered Users Posts: 1,987 ✭✭✭Ziycon


    I'd prefer it not to be part of the theme in case the theme changes hence the plugin route.


  • Registered Users Posts: 6,486 ✭✭✭daymobrew


    For stuff like this I use shortcodes that I put where I want.

    You write a plugin and your shortcode function does what it needs to and returns a string of html that will appear in the page.
    The plugin is independent of the theme and is uploaded to the wp-content/plugins directory and activated in the Dashboard.

    As an example, here is a tiny plugin that I wrote for generating anchor and target links:
    [PHP]<?php
    /*
    Plugin Name: Anchor/Target shortcodes
    Plugin URI: http://www.damiencarbery.com
    Description: Shortcodes for generating anchor and target links.
    Author: Damien Carbery
    Version: 0.1

    $Id: anchor-target-shortcodes.php 2297 2014-01-01 21:53:29Z damien $
    */


    function ats_helper_shortcode($atts, $content, $code) {
    switch ($code) {
    // [anchor_link text='More Info' name='target']
    case 'anchor_link':
    extract(shortcode_atts(array(
    'name' => '',
    'text' => '',
    ), $atts));
    return '<a href="#'.$name.'">'.$text.'</a>';
    break;
    // [target_link name='target']
    case 'target_link':
    extract(shortcode_atts(array(
    'name' => '',
    ), $atts));
    return '<a id="'.$name.'"></a>';
    break;

    default:
    return '';
    }
    }

    add_shortcode('anchor_link', 'ats_helper_shortcode');
    add_shortcode('target_link', 'ats_helper_shortcode');
    ?>[/PHP]


  • Registered Users Posts: 241 ✭✭fcrossen


    A plugin is the best way to do this.

    There are plenty of basic plugin tutorials (https://codex.wordpress.org/Writing_a_Plugin) but you should only need the most basic skeleton of a plugin, perhaps even a single file (like the "Hello Dolly" sample that ships with Wordpress). Look at the ""the_content" filter to change the page content.

    You will need to sniff out the current page from the wp_query object (make it global in your plugin file).


Advertisement