• Resolved Sam

    (@forbiddenchunk)


    Hi,

    I have been asked do the following but don’t understand what is being asked of me;

    Create a WordPress shortcode that displays some text within a date range on a page of content. The text and both dates should be provided within the shortcode.

    The form of the shortcode should follow this outline:

    [datetext from=”start date” to=“end date”] text to be displayed [/datetext]

Viewing 3 replies - 1 through 3 (of 3 total)
  • That looks to me like a shortcode calling for output or control from a plugin, and you would simply paste it into the text on your page (or possibly within a text widget) and then “fill in the blanks”:

    [datetext from=”???” to=“???”] What do you want displayed here? [/datetext]

    Each theme and plugin has its own Support sub-forum here, so you might take a look there for more details as to the date format to be used.

    Thread Starter Sam

    (@forbiddenchunk)

    Hi, thanks for getting back to me I was able to get it working but for some reason I am still getting “” appearing round the text.

    function startDate($atts, $content = null) {
    extract(shortcode_atts(array(
    “from” => ‘$from’
    ), $atts));
    extract(shortcode_atts(array(
    “to” => ‘$to’
    ), $atts));
    return ‘<h3>’.$content.'</h3>The date starts on ‘.$from.’ and ends on ‘.$to.”;

    }

    add_shortcode(“datetext”, “startDate”);

    With the following in the page/post

    [datetext from=”10/09/2015” to=“13/09/2015”] The event will begin and end on the following dates;[/datetext]

    Which then outputs the following;

    The event will begin and end on the following dates;

    The date starts on ”10/09/2015” and ends on “13/09/2015”

    How Do I remove the “”?

    Just guessing here, but maybe try using this to see what you get:

    add_shortcode('datetext', 'startDate');

    If you get the apostrophes in place of the quotation marks, then maybe try this:

    add_shortcode(datetext, startDate);

    If either of those cause a crash and/or you still get the quotation marks anyway, then either something somewhere else is adding them or else the ‘add_shortcode’ line is not being parsed properly.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How do I create shortcodes’ is closed to new replies.