Shortcode with parameters inside parameters

The days of the week shortcodes aren’t needed. Also, the way you’re trying to use them isn’t allowed. Why not just use the title and do what you want in the books shortcode?

function books($atts, $content = null) {
  $atts = shortcode_atts( [
    "name" => '',
    "day" => '',
    "title" => '',
  ], $atts );

  $atts[ 'day' ] = ucfirst( strtolower( $atts[ 'day' ] ) );

  //* If you want to change the URL, you could switch on the day
  switch( $atts[ 'day' ] ) {
    case 'Monday':
      $url="https://example.com/";
      break;
    case 'Tuesday':
      $url="https://someotherurl.com/";
      break;
    //* etc.
  }

  return sprintf( 
    '<div class="cite">%1$s%2$s | %3$s</div>',
    '' === $atts[ 'name' ] ? '' : $atts[ 'name' ] . ' read a book',
    '' === $atts[ 'day' ] ? '' : 
      sprintf( ' on <a href="https://wordpress.stackexchange.com/questions/296007/%1$s" target="_blank">%2$s</a>', $atts[ 'day' ], $url ),
    $atts[ 'title' ]
);

Leave a Comment