Where to add custom code for search results?

Home Forums Calendar Products Events Calendar PRO Where to add custom code for search results?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1271412
    Alnoah
    Participant

    Hi there,

    I’m looking to force list view for search results (on mobile and desktop). I found another topic which has a chunk of code I’d like to try out:

    Forcing list view for search results

    Here is the code`jQuery( document ).ready( function( $ ) {

    if ( ‘object’ !== typeof tribe_ev ) return;

    var existingSearch = tribe_ev.state.url_params;

    $( tribe_ev.events ).on( ‘tribe_ev_collectParams’, function() {
    var issearch = tribe_ev.state.url_params.match(/tribe\-bar\-search/g);

    if(issearch) {
    window.location = ‘/events/?’ + tribe_ev.state.url_params + ‘&eventDisplay=list’;
    }

    } );
    } );`

    Where do I add this code specifically? I’m a newbie.

    Thanks!

    #1271450
    Cliff
    Member

    Hi. Thanks for pointing to that for the possible solution.

    I added a comment there with the new, full code snippet.

    As far as how to implement it into your own site… welcome to WordPress customizing!

    Best practice for adding custom code (like to implement a PHP snippet to modify The Events Calendar) is to create a functionality plugin, unless it’s something specific to your theme, in which case best practice is to make sure you’re using a child theme, then add the customization to your child theme’s functions.php file.

    Note: do not include the beginning <?php line of the snippet. It’s needed to enable syntax highlighting on Gist, but you shouldn’t copy/paste that part if just pasting into your functionality plugin or midway through your child theme’s functions.php file.

    I hope this information helps!

    Please let me know if you have any follow-up questions on this topic.

    #1271456
    Alnoah
    Participant

    Hi Cliff,

    I really appreciate your help here. I added the code you updated to a blank functionality plugin template to create my own plugin as you suggested. I’ve uploaded it here.

    Where do I now upload this zip file?

    Thanks,
    Fowaz

    #1271927
    Alnoah
    Participant

    Does anyone know where I would upload this zip file?

    Thanks in advance!

    #1272368
    Cliff
    Member

    Thanks for sharing.

    Your readme.txt file can be deleted. It’s not in the proper format and those code comments are already added to your .php file, after the opening <?php tag, which is correct. The readme.txt file is not necessary for your own plugin that you don’t share with / publish to others, but including it in the proper format is best practice, especially the changelog section in my opinion.

    Your .php file is just fine except that you should not include the closing PHP tag: ?> at the end of the file.

    Other than that, it’s suggested to edit the plugin header information–the comments at the top of your .php file.

    I made these and some other minor edits and uploaded it into an installable plugin zip: https://cl.ly/0830163p0U0r

    You can go to wp-admin > Plugins > Add New > Upload and install it that way. I hope it works for you.

    #1283101
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Where to add custom code for search results?’ is closed to new replies.