One approach is:
//...
// this is the resulted paragraph without the enclosing <p> and </p>
$first_para_inner_text = $matches [1] [1]; // <-- the index changed
$link = get_permalink($post);
// rebuilding the p
$first_para="<p>" . $first_para_inner_text . ' <a href="'.$link.'">Read More</a></p>';
echo $first_para;
Not tested, but you may get the idea. Just need to modify/change some parts of your code with this.
Related Posts:
- Word Count Function Preventing Permalink Editing
- Custom excerpt function re-factoring
- How to remove the excerpt in the Dzonia Lite theme
- Error when adding excerpt to the content through functions.php
- Query Pages and post excerpts dynamically
- My custom get_the_excerpt() can’t get excerpt by ID
- How to remove the space before the ellipsis in excerpt?
- Child Theme’s Read More Text
- Cannot figure out how to add a read more link to a manual excerpt. Please help
- How to trim content AND retain HTML?
- Using tag to output text in Genesis?
- Merging two excerpt functions to work with conditions
- Error Warning: Declaration of description_walker::start_el after PHP upgrade [duplicate]
- Mega Menu Walker
- Autoloading in Child Theme
- How to add a class to the attachment images
- How to call a function only once (global variable scope)
- Multiple is_page() in page.php
- Is it possible to get a theme customizer setting from wp.customize using jquery?
- How to correct schedule my event weekly with wp_schedule_event()
- Execute a shortcode when clicking on a image
- Limit the_excerpt with max of x characters
- add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
- How can update custom meta for all posts
- Change logo based on incoming domain
- wrong php date()?
- How do I fetch all comments per post via WP REST API?
- Count the number of times the search form template gets included on a page
- PHP code inside shortcodes
- How to Display a Single Post Excerpt
- Using More Tag in Combination with the_excerpt
- How do I display a user’s previous orders as a select box option on a product?
- Remove meta description on certain pages
- Image media upload metabox
- How to combine wordpress_logged_in cookies in one cookie?
- How to store data from multiple forms using ajax and php
- How to control WordPress image metadata (using Imagick)?
- Use DOMDocument with ob_start breaks my HTML code
- Display a specific category of products in shop page and disable code for specific actions
- Removing “wpautop” (auto tags) only on certain pages?
- trigger html cleanup for all posts
- Catchable fatal error: Object of class stdClass could not be converted to string after WP 4.7
- Add class to group inner container
- Use .php file as page instead of wordpress page & template file?
- Illegal string offset in PHP function
- Find hours between post_date and post_date_gmt
- Run a code only on theme activation only during first activation
- Shortcode from a function not working
- Is it possible to return content, and then also continue to do other things?
- Displaying text if post was within 5 hours
- Creating WordPress Shortcode with Variable
- Convert the_permalink() function output into string
- Adding a tag_ID column into Categories inside the admin dashboard?
- Add meta tags to a custom header
- get_current_site() is undefined
- How to use mysql LIKE with wpdb?
- Automatically Add Page Links to Nav Menu
- blank white page when post/update/change option etc
- Function sanitize_title() does not appear to be working
- writing an unique php function to be used on my website
- Displaying Event within two given time frames
- How to prevent a function from running based on host (ie web vs local)?
- How to call custom function outside from the admin page?
- Problem in replacing the_content with the_excerpt()
- How to change the author box selection on a post to a custom taxonomy
- Output product category link from WP_Query
- Adding onload to body for certain pages
- Delete images from media library when user deletes an image from ACF Gallery
- Reject all malicious URL requests functions.php
- How to send a php var to jQuery Ajax call with two different file
- Change wordpress’ database data using ajax – how to get current user id?
- not outputting medium size image URL
- Best way to use variables in multiple functions?
- Notice: Undefined variable
- Cannot fetch posts with certain ‘product_cat’. WP_Query is empty
- How to override WooCommerce Order Item Meta with data from Cart?
- Taxonomy Child Term, Counter is staying on 0
- Access to “My Site” is missing from the admin bar
- Detect what link user clicks and Redirect to a specific page for logged in users only
- Offset with ajax load more posts duplicates
- Need help with PHP functions
- Using get_theme_mod with checkbox to display content
- Archive page if else not working for post_excerpt and post_content
- WordPress styling recent post
- Break a WordPress function to run in patches and re-continue
- Pagenav Not appearing on custom Template
- syntax error unexpected ‘}’ at 364 line
- get_post_meta no longer working
- Highlight posts currently being edited on multiple editor site?
- Showing all post from all post type in admin backstage
- Shortcode to include PHP file, pass various parameters to include?
- Why can’t I include echo inside a variable? [closed]
- Assign new post author IF another user in custom field on post transition
- Create and publish a new post every Monday, listing the post titles and links to the posts published during the previous week
- How do I change the Go To Categories link in the term_updated_messages
- WooCommerce – Show ‘Sales’ badge on variable products where only some variations have sales price [closed]
- Dynamic Email Handler with ‘header (“Location: …’
- WooCommerce: write featured image dimensions to custom fields in product’
- Generate and upload screenshot as featured image for user-submitted post
- transition_post_status hook, works – but not if the post is new