1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Add PHP Shortcode for current date?

Discussion in 'Blogging' started by Quattroporte, Aug 14, 2013.

  1. Quattroporte

    Quattroporte Regular Member

    Joined:
    Nov 18, 2012
    Messages:
    469
    Likes Received:
    170
    How can I add a shortcode that displays the current date?

    I want something like "Working as of Wednesday, August 14, 2013". I know some code has to be entered in one the theme's files, but I'm not sure which one.

    Any help is appreciated. :)
     
  2. Gogol

    Gogol Elite Member

    Joined:
    Sep 10, 2010
    Messages:
    3,066
    Likes Received:
    2,872
    Gender:
    Male
    Code:
    
    function date_wp
    ( $atts ){  
       return date('d/m/Y h:i:s'); 
    } 
    add_shortcode( 'foobar', 'date_wp' );
    
    
     
    • Thanks Thanks x 1
  3. Quattroporte

    Quattroporte Regular Member

    Joined:
    Nov 18, 2012
    Messages:
    469
    Likes Received:
    170
    Which theme file would I add this too? And I take it I'd just have to add [date_wp] to my WP posts and it would work?
     
  4. Gogol

    Gogol Elite Member

    Joined:
    Sep 10, 2010
    Messages:
    3,066
    Likes Received:
    2,872
    Gender:
    Male
    Add it to functions.php
    call [foobar] (or rename it to something more interesting)
     
    • Thanks Thanks x 1