First, your return
statement is before you actually add the meta data, so your hook is terminating before it can do that. Remember that return
ends the function it’s within, so only put it at the very end or in places you want it to short-circuit.
Second, your RegEx is a little off; you shouldn’t be using the ^ and $ markers since you’re trying to match a domain name anywhere within the text.
Here’s a patter that may do the job:
/(?<=^|\/|\s)([\w\-\.]+\.\w+)(?=^|\/|\s)/
This will match bob.com
, but not [email protected]
because the (?<=)
and (?=)
bits tells it to only consider matches that are preceded/followed by the beginning/end of the string, a forward slash, or a whitespace character. You’ll probably need to play around with those lists to make sure it doesn’t accidentally grab something else, or miss a valid entry surrounded by other stuff like HTML.
Related Posts:
- Only display posts after current date
- Apply the_title() filter in post & page title, but not in menu title
- Update post counts (published, draft, unattached) in admin interface
- How to protect pages with double authentication: password + email (in custom field)
- Removing any and all inline styles from the_content()
- How set featured posts using checkbox in post edit screen?
- Removing filter dropdown in posts table (in this case Yoast SEO)
- Get old values for post before saving new ones
- Add a checkbox to post screen that adds a class to the title
- How does filter the_posts work?
- Custom Field in Featured image for A particular post
- How to publish a post with empty title and empty content?
- How to add a “publish” link to the quick actions
- Convert custom fields to post categories
- Update all posts automatically when using post_meta
- Why is wordpress removing some unicode characters (e.g. some emojis) when I save my post?
- I am trying to create a simple frontend form for posting
- Prevent duplicate posts in wp_insert_post using custom fields
- HTML code in Custom field
- Better post meta efficiency?
- How to show posts rank based on custom field value
- how to display post content without post image?
- Add custom field to all posts in specific category
- Exclude category on blog list page
- How to remove_filter that filters iframes in posts? [duplicate]
- Adding a Nav menu to post admin
- meta_box or custom_field as a second tinymce post-instance?
- Filter posts by author and category simultaneously
- Guest Author – How to modify my custom function code if the guest author URL will follow a particular pattern/format?
- Filter post before *editing*
- Filter/Remove HTML Elements on all posts and pages
- Create A Metabox For A Custom Field
- Paragraphs removed when using get_post_custom()?
- get_post_custom stripping styling issue
- Change post format using custom field
- Populating a page with content from post custom fields
- How to change what the post creation page looks like?
- Sanitizing `wp_editor();` Values for Database, Edit, and Display
- How can I make existing custom fields easier to edit/add in my theme?
- how “manage_posts_custom_column” action hook relate to “manage_${post_type}_columns” filter hook?
- Add custom fields to post programmatically
- How to get Advanced Custom Field Value According using POST ID? [closed]
- If specific user role then sticky post
- Autoremove empty custom fields
- How to add a custom field after wp post
- Custom fields on a virtual page
- Getting post id from wp_insert_post_data function?
- What Is meta_id In wp_postmeta?
- Get a custom field of all posts on current blog page
- the_posts filter been called multiple time
- Filter Posts By Tag
- Custom excerpt length filter doesn’t work
- How can i do something after head like adding a hook for after head but before post
- Amend wordpress password function
- Custom Post Templates
- Add custom field automatically (add_post_meta) with value based on number of words of article
- Global $post not working in OOP function WordPress
- How can I remove posts of a certain category from homepage after a specified time period?
- How can I get a post field value using javascript?
- Automatic value for custom fields for posts
- How to generate numbers indistinguishable for the IDs of the posts
- Modify WP_Post before processing
- Understanding and using metaboxes in posts
- How to filter posts that belong to a specific category only if that is the only category
- How to retrieve the postID in a “image_send_to_editor” hook function?
- Filter Custom Post Type by Category with Ajax
- Ajax posts filter by date, comments, top views, top likes
- Duplicating Table of Contents for Paginated Post
- How to add Tags Filter in wordpress admin dashboard
- pre_get_posts query between 2 dates (date stored in custom post meta)
- Applying $posts_clauses filter to specific queries only
- how to remove dash (-) post status from post title on posts listing page wordpress
- Admin Posts Table Column Fitlering is not working for Custom Post Type
- Get latest posts from WordPress site without header, menu and sidebar
- Modify Image Source With The_Content Filter?
- Guest Author – How to display posts on /author/ archive page
- WP_Query orderby not working with meta_value_num and menu_order
- How can I sort posts by the date and a custom meta field?
- How do I correctly set up a WP-Query to only show upcoming event-posts?
- What is the filter or hook to add admin controls to posts on the front end?
- How to display Common posts from specific Tag & Category with Shortcode
- Change post order random through out the entire WordPress
- use wpml_post_language_details function other plugin based on $post->ID [closed]
- How to hide html tags on revision comparison pages?
- Add filter by custom field to block of posts
- Ajax post filters not working
- Default to ‘all’ view on the ‘edit-post’ screen for authors
- Display Meta Values in Custom Filter – Admin Custom Posts
- Automatically add custom fields value to wordpress post
- How to filter my search in post if contains a word in title, content or excerpt?
- More then one menu items are assigned with “current-menu-item” class
- Update post_content everytime a custom post is opened in backend
- Is there a way to notify specific users when new posts are published to specific pages?
- Posts and Attachments with “Published” status in Search
- MySql query to get posts with all meta and terms
- Categories list into registration form
- Add a custom meta box in the post options that loads some html code in the header
- Query Posts With Over 1000 Views
- How to allow visitors to filter posts by multiple taxonomies
- Cannot retrieve a custom RSS field from posts