Event List is not displaying shortcodes correctly

Home Forums Calendar Products Events Calendar PRO Event List is not displaying shortcodes correctly

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1393512
    April
    Participant

    I’ve created a shortcode to call the Event Title since most of our Events have the same description and we just want to update Event meta dynamically.

    function shortcode_eventtitle() {
      return tribe_get_events_title($postID);
    }
    add_shortcode('eventtitle', 'shortcode_eventtitle');

    At first, the shortcode on a list view didn’t appear at all, then I added a filter

    add_filter( 'tribe_events_excerpt_allow_shortcode', '__return_true' );

    which made the shortcode appear, but instead of getting the Event Name, it’s showing the current page name.

    Any ideas to make this work?

    #1395175
    Patricia
    Member

    Hey April,

    Thank you for reaching out to us!

    Could you please replace tribe_get_events_title() with the_title_attribute() and let me know if it helps you to solve the problem?

    Thanks,

    Patricia

    #1395646
    April
    Participant

    Hi Patricia,

    that doesn’t solve it I’m afraid. The output is weird now and shortcode is echoed on a places where it shouldn’t be. Please have a look where it echoes and where it’s placed in the backend.

    Here are the functions I made for shortcode purposes.

    /********************************************************************
    Add eventdate shortcode
    ********************************************************************/
    function shortcode_eventdate() {
      return tribe_get_start_date(null, false, 'F j, Y - g:i a');
    }
    add_shortcode('eventdate', 'shortcode_eventdate');
    
    /********************************************************************
    Add eventvenue shortcode
    ********************************************************************/
    function shortcode_eventvenue() {
      return tribe_get_venue( $postID );
    }
    add_shortcode('eventvenue', 'shortcode_eventvenue');
    
    /********************************************************************
    Add eventtitle shortcode
    ********************************************************************/
    function shortcode_eventtitle() {
      return the_title_attribute();
    }
    add_shortcode('eventtitle', 'shortcode_eventtitle');
    
    /********************************************************************
    Add eventcategory shortcode
    ********************************************************************/
    function shortcode_eventcategory() {
      return tribe_get_event_taxonomy(
          get_the_id(), array(
    				'before'       => '',
    				'sep'          => ', ',
    				'after'        => '',
    				'label'        => null, // An appropriate plural/singular label will be provided
    				'label_before' => '<dt>',
    				'label_after'  => '</dt>',
    				'wrap_before'  => '<dd class="tribe-events-event-categories">',
    				'wrap_after'   => '</dd>',
    			)
          );
    }
    add_shortcode('eventcategory', 'shortcode_eventcategory');
    
    /********************************************************************
    Add eventstarttime shortcode
    ********************************************************************/
    function shortcode_eventstarttime() {
      return tribe_get_start_date($post, false, $format = 'g:i a' );
    }
    add_shortcode('eventstarttime', 'shortcode_eventstarttime');
    
    /********************************************************************
    Add eventendtime shortcode
    ********************************************************************/
    function shortcode_eventendtime() {
      return tribe_get_end_date($post, false, $format = 'g:i a' );
    }
    add_shortcode('eventendtime', 'shortcode_eventendtime');
    
    add_filter( 'tribe_events_excerpt_allow_shortcode', '__return_true' );

    Note that I’ve changed the the_title_attribute() per your suggestion. Any other ideas?

    #1396881
    Patricia
    Member

    Hi April!

    Oh, this is happening because we didn’t set the title attribute for use in PHP. Please replace:

    return the_title_attribute();

    with:

    return the_title_attribute('echo=0');

    You will find more info about the_title_attribute here:

    https://codex.wordpress.org/Function_Reference/the_title_attribute

    I’ve tested the shortcode here and everything is working as expected now šŸ™‚

    I hope this helps! If you have any other questions at all please feel free to let me know and Iā€™d be happy to help as best I can!

    Cheers,

    Patricia

    #1401123
    April
    Participant

    Worked! Thanks!

    #1401289
    Patricia
    Member

    Hi April,

    You are welcome šŸ™‚ I’m glad to hear that everything is working as expected now! If you need an assistance again or have other concerns, please feel free to open up a new thread, we’ll be more than happy to help you!

    Cheers,

    Patricia

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Event List is not displaying shortcodes correctly’ is closed to new replies.