NEVER EVER alter any template or file in a theme or plugin that you did not author, and this goes for any core file as well. There is no way to protect the code that you alter or add in any of those files, except maybe changing file permissions, but then again, you will run into other issues
ALL customizations should and must be made in either a child theme or a custom plugin. Code like shortcodes as in your question must always go into a custom made plugin as shortcodes add functionality to your site and not your theme.
You should definitely go and read the following post
This is one of the most important things that you need to consider when customizing anything for a site
Related Posts:
- How to manually fix the WordPress gallery code using PHP in functions.php?
- Encode text string being appended as query to URL [closed]
- Display a text message if the shortcode is not found?
- How to return a string that has a variable inside in a shortcode?
- Run shortcode at certain resolution
- Passing a shortcode attribute to a sub-function
- post meta value as shortcode parameter
- the_title() & the_content() are retrieving Post details inside a Page, after calling a shortcode
- Audio tags around Mp3 URL in content
- Loading page template into shortcode
- How to add Shortcode (font awesome) in widget title?
- Wrap each shortcode in array to div
- Placing the_content inside shortcode not working
- Autogenerate shortcodes from an array of strings
- How do I add text in a shortcode?
- How to Insert Shortcodes into Theme?
- Template part inside shortcode, unexpected reult
- Shortcode Inside Class Not Working
- is_page “range” for if statement?
- How can I generate random numbers inside my shortcodes on each implementation?
- Shortcode API: How to get name that matched shortcode RegEx?
- Shortcode content filter?
- Custom Theme, Custom shortcode not working
- Why is file_get_contents returning page source?
- Plugin CSS not enqueing
- Different loop output every x posts in custom post type
- Showing content from one page on another
- Showing a different gallery in a seperate post
- Create own WordPress shortcode gallery
- Get value from shortcode to do something
- WordPress Shortcodes.. printf is outputting a random number… Can’t figure out WHY?
- Custom shortcode outputs plain text instead of HTML at top of post
- How to use wp_add_inline_style for custom CSS added via shortcode?
- Displaying recent posts on static page with template-part via shortcode
- Excecuting php function in shortcode
- Returning data instead of echoing/printing
- displaying content that includes shortcodes within an echo
- List taxonomy term slugs within shortcode (do_shortcode)
- Display Data in Table from External Database in WP using Shortcodes
- do_action(), iFrame Gets Displayed Despite Password Protection [closed]
- Using Shortcode to Grab Archive Listing, Separate by Year
- Capitalize Shortcode Value on Output
- Why is my str_replace not working on short code submitted by front-end?
- List all blogs, but exclude the main site
- Shortcode not staying inside div tag
- Shortcode to pull posts
- PHP code inside Shortcode
- Help Fallback (thumbnail)
- How to return a string that has a jQuery and Ajax inside in a shortcode?
- Shortcode function doesnt work without caption
- Action Hook Inside WordPress Plugin Shortcode
- How can I include the user id inside of a shortcode php output?
- PHP Helper Class to create shortcodes
- Create special button on WP Tiny MCE Posts Editor for Shortcodes
- Change Spaces to Dashes?
- Updating Metadata with Shortcode
- using shortcodes inside gravity forms
- How to Create custom block for displaying information in content section which act like shortcode
- Display logged in user name and lastname on page
- Create shortcode for metabox gallery
- Replace background image with post thumbnail in shortcode
- couldnt show short code atts in category
- Conditional formatting on data fetched from MYSQL
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- Advanced Custom Forms PHP formatting for do_shortcode
- overwrite wordpress gallery with custom gallery shortcode
- How to use Contact Form 7 shortcode value in a page?
- Display current user metadata on WordPress page
- Add Shortcode to ::before class
- Reload page with a different shortcode when a user selects from a dropdown
- How Can I Display the Last Modified Date for User Profiles on WordPress?
- Shortcode’s output to use as other shortcode’s parameter
- Show products per shortcode
- Open/closed function [closed]
- What is wrong with this shortcode? to include external php file in WordPress posts
- Need to Echo A Url path to show on a wordpress page
- Add two or multiple functions in WordPress Post or Page
- Shortcode Works for Logged in Users but Not Working for Guest
- perform mathematical operation on shortcode
- Update same content in multiple posts at once?
- Formatting Shortcode to Display in Visual Mode
- problem multisite with blog id
- How to pass parameter that ends up being part of a class name with wordpress shortcode
- Create dynamic content from one WP page to multiple other pages
- Shortcode Display From WordPress Dashboard Page Without Using post_id
- Do_shortcode on PHP file outside theme ALMOST works
- Overwriting a Shortcode
- Custom Shortcode with Dynamic Button
- Whats wrong with my code? Need To add String to shortcode? [closed]
- A next page function with shortcode?
- using a shortcode in a hyperlink
- Shortcode for Visual Composer Grid fails turning string to integer
- Display total count of products in orders of a specific order status
- why css file not link?how to create permalink?
- Show Login Errors In WordPress/Elementor (Code “works”, but breaks site)
- Shortcode Displays 2 times
- Adding a css class to the gallery
- Strip and print only the numbers found in current’s post excerpt (even if they are without space)
- How to make this shortcode not refresh the whole page when i use it on frontend
- “Joined in” or “Member since” displayed on single store page and then using shortcode to add