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
- 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?
- Custom Field in Featured image for A particular post
- How to publish a post with empty title and empty content?
- Convert custom fields to post categories
- Why is wordpress removing some unicode characters (e.g. some emojis) when I save my post?
- Prevent duplicate posts in wp_insert_post using custom fields
- Adding a Nav menu to post admin
- Filter posts by author and category simultaneously
- Filter/Remove HTML Elements on all posts and pages
- Paragraphs removed when using get_post_custom()?
- get_post_custom stripping styling issue
- Populating a page with content from post custom fields
- how “manage_posts_custom_column” action hook relate to “manage_${post_type}_columns” filter hook?
- Autoremove empty custom fields
- Getting post id from wp_insert_post_data function?
- How can I remove posts of a certain category from homepage after a specified time period?
- Automatic value for custom fields for posts
- Modify WP_Post before processing
- How to add Tags Filter in wordpress admin dashboard
- Applying $posts_clauses filter to specific queries only
- Admin Posts Table Column Fitlering is not working for Custom Post Type
- 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
- 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?
- 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
- Cannot retrieve a custom RSS field from posts
- Hooking into the post editing screen for an existing page only
- Trying to alter the post_content through the_post
- How to rate a post from Admin Side / Manually?
- Add filter to the end of the post
- Get post content with all filters applied, knowing post id
- Is it possible to filter the main loop to exclude posts from a specific category?
- query post limits
- Filtering posts on Post Administration Page by Week Number instead of by Month
- Change the default blog post post attribute template name from “default template” to something else
- Is it possible to add a shortcode below post title?
- Post filtering is returning blank page
- Updating permalink structure using ‘post_link’ filter results in 404 error for posts
- Add two custom fields as a default to the “new post” page.
- Add multiple meta keys to a post at once
- Exists filter or action that change Add New Post link?
- saving/reading custom field value does not work – no value gets POSTed
- Adding external field to my post form (admin side) and to post show (frontend side)
- wp_list_categories() Exclude All Categories Except One
- Get current taxonomy and display query accordingly
- Will multiple category descriptions effect my search engine optimization?
- Display custom post front end filter by ACF equals current user
- Post picker custom field on page
- How do I display main query posts in random order using add_filter
- Rewrite image links from attachment id to attachment link
- Restricting displayed posts to posts from only select authors
- the wp_post_update isn’t working all the time
- How to add a custom class attribute into code wrapper? [duplicate]
- Filtering private Posts
- how to filter posts by category without page load (ajax) in wordpress?
- Remove status ‘archived’ from the default post and page view
- long-title posts do not want published
- Is there a way to save different data when USER interacts with the same POST?
- How to add a block to a category page?
- How do i search post by jquery datepicker?
- Add id attribute to h1 element of wordpress post
- How to get value of a selected option from select tag and use it in WP_query to filter posts?
- show only one category and filter by tag
- WP_Query sort by meta_value_num or date
- Prevent WordPress from putting around specific element
- Creating Ordered Query using Meta_key
- Auto populate custom fields by post date
- Is it possible to completely replace a post with an action/filter?
- ACF Relationship – Get Parent’s Post Object
- How to get the postID inside ‘content_save_pre’? Other hook?
- Filter question list on substring of metavalue
- Add review box by function at top or bottom of content
- How can I set and update the the_date according to a custom field of the post
- Get results from the main wp_query
- WP Query between posts custom fields [duplicate]
- get_the_ID() fails the first time, returns a value the second time it’s called
- Using Post ID and Page ID in same function
- Apply comment to different post (not the current post) [duplicate]
- How to only allow post to be deleted if custom field doesn’t exist
- How do I insert a custom field in a user submitted post?
- wp_query posts sorting doesn’t work
- Display a custom field rating system in the front end
- How to detect if an ACF custom-field is really in use?
- Filters do not work when there are multiple (one works)