The best practice in the WordPress world is to “escape late” i.e. at the point of output. While the two examples are effectively the same, the first one would be more effective if that code is ever refactored and the value of $portf_icon changes between where it’s first assigned & where it’s output.
Related Posts:
- Sanitizing integer input for update_post_meta
- Should I sanitize custom post meta if it is going to be escaped later?
- Correct processing of `$_POST`, following WordPress Coding Standards
- How to sanitize post meta field value?
- Copy content stored in meta to post content
- Can A Post Meta Field Store multiple values that are not in an array?
- Data not displaying in text field
- Proper Way to Sanitize Meta Input
- Extend file format support for post thumbnails
- Explanation of update_post_(meta/term)_cache
- Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does
- Adding meta tag without plugin
- What is the different between an attachment in wp_posts and an attachment in wp_postmeta?
- if get_post_meta is empty do something
- Meta compare with date (stored as string) not working
- How to sanitize select box values in post meta?
- How to update/insert custom field(post meta) data with wordpress REST API?
- Remove WordPress.org Meta link
- Front-end update_post_meta snippet displays white screen?
- Give extra post-meta to RSS feeds
- How to get meta value in wp_attachment_metadata
- Clean up output added via wp_head()
- Short of raw SQL, can I query for multiple attachment metadata that have a given array key?
- Get post from meta_key and meta_value
- get_post_meta returns bool(false)
- How to get custom post type to display post meta on archive pages?
- Mass importing json data into custom fields (postmeta)
- How to echo get_post_meta (Fluent-Framework)
- WP_POSTMETA changes site crash
- meta_post_meta return value 1
- How to use post_id with a Class?
- Set default Custom Post Meta Value
- how do I set a schedule event to modify all posts’s meta value weekly or monthly?
- INSERT ON DUPLICATE KEY UPDATE failes in postmeta table
- Set Checkbox as checked by default
- WordPress front-end media (image) upload ERROR!
- running function during post save and adding variable to post meta
- replacing the_autor or make callback
- Some post meta fields stop saving after a few successful saves
- Can’t access post meta on new post creation (cpt)
- Save an array of values in the post meta box
- get_post_meta() empty in preview WHEN custom post is published [closed]
- Add Embed.ly API objects to post_meta on update
- Editing does not change post_name
- Compare string with post id in wpdb and do stuff when match is found
- $wpdb class updating meta_value using Ajax [closed]
- Is it possible to retrieve a post and its metadata at the same time?
- cleaning up safely wordpress wp_postmeta table
- How to selected which tags to print, instead of printing the whole tag list?
- Why does get_transient() always return string even if integer set?
- query posts and split meta information into separate div’s
- How do I manage custom meta in post revisions in the Block Editor era?
- Generate metadata for cloud images
- Is there a way to disable post meta caching for development?
- How to extract data from a post meta
- Get post_meta from specific post [closed]
- update_post_meta not working?
- Change wordpress meta tag description using WP functions
- getting the post_id from the post_meta
- troubles with get_post_meta (and saving it)
- Cant create or update meta fields using WordPress REST API
- Filter posts by meta key
- Display current ranking of post as a number in post title
- delete duplicates wp_postmeta
- Post Thumbnail missing when using webp format while sharing
- Bulk Update Post Meta Values from Different Post via Rest Api
- update_post_meta() is not saving the value
- Only show meta on one post type on search results page
- How to register post meta with multi level arrays?
- If I disable screen options, does WP still try to update post meta?
- Can we have duplicate key pair values in post meta data?
- I created a Custom Meta Box but it is not displaying the value on my post page
- Meta data being pulled from wp-login.php
- Is it possible to pass an whole array using custom field in wordpress?
- Get post content before rendering
- wp_insert_post inside save_post adds wrong metadata to inserted post
- Rename image filename using ‘media_handle_upload’
- Update Post metafield of specific categories
- rendering open graph meta tags in wordpress
- Using Self Hosted Video URL With Custom Fields
- Multiple postmeta values to the same post_id/meta_key combination?
- get_post_meta not work in php foreach
- Why are my custom metaboxes not updating the post meta?
- Problem serializing single quote and double quote into post meta
- Storing post_meta fields in array
- Performace on 1 million plus meta fields vs 1 field with 1 million multi array
- Fetching array of postmeta with $wpdb and in_array conditional
- Piklist File Upload
- wp_schedule_event not working
- how to echo/display the custom field value in specific custom field name?
- update_post_meta() not working in bulk option
- How to update the ‘modified_time’ of a post ONLY when content is changed?
- Multiple If else statements on Search Result Page
- WordPress join posts with meta values of array type
- Export posts with postmeta without ID?
- get_children filter with postmeta
- How can I display my meta value in a textarea? [closed]
- delete blank space in post_meta empty [closed]
- wordpress query making site very slow
- if condition from post_meta not working in save_post