Home › Forums › Calendar Products › Events Calendar PRO › Where to add custom code for search results?
- This topic has 6 replies, 2 voices, and was last updated 8 years, 11 months ago by
Alnoah.
-
AuthorPosts
-
April 18, 2017 at 7:20 pm #1271412
Alnoah
ParticipantHi 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:
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!
April 18, 2017 at 8:45 pm #1271450Cliff
MemberHi. 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.
April 18, 2017 at 9:02 pm #1271456Alnoah
ParticipantHi 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,
FowazApril 19, 2017 at 7:08 pm #1271927Alnoah
ParticipantDoes anyone know where I would upload this zip file?
Thanks in advance!
April 20, 2017 at 1:09 pm #1272368Cliff
MemberThanks 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.
May 12, 2017 at 9:35 am #1283101Support Droid
KeymasterHey 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 -
AuthorPosts
- The topic ‘Where to add custom code for search results?’ is closed to new replies.
