This is really more of a general PHP question, but this will do the trick:
$author_desc="<div class="td-author-description">";
$author_desc .= get_the_author_meta( 'description', $author_id );
$author_desc .= '</div>';
$dom = new DOMDocument;
$dom->loadHTML( mb_convert_encoding( $author_desc, 'HTML-ENTITIES', 'UTF-8' ) );
$sxe = simplexml_import_dom( $dom );
// Process all <a> nodes with an href attribute
foreach ( $sxe->xpath( '//a[@href]' ) as $a) {
if ( empty( $a['rel'] ) ) {
$a['rel'] = 'nofollow';
} else {
$a['rel'] .= ' nofollow';
}
}
$author_desc = $dom->saveHTML();
$buffy .= $author_desc;
Replace the original code in your question with the code in this answer (this is based on the full code that you posted here).
Code adapted from this answer on Stack Overflow. Encoding fix via this post.
Related Posts:
- User registration followed by automatic login
- wp_insert_user role not working
- How to find cause of PHP notices with no stack trace?
- How to paginate a list of custom taxonomy terms?
- reason of splitting theme files to multiple files
- Limit the Excerpt field in WP-Admin in words
- wordpress separate registration for different roles
- Problem with Woocommerce REST API Authentication
- How to get custom image size for image uploaded in Customizer
- Passing POST data from one WP post to another
- How to change / delete product short description in Woocommerce
- How do I add HTML to a PHP function [closed]
- register_activation_hook isn’t adding table to DB
- how to get the value of time left for a transient
- Remove query string specific key value
- is_page “range” for if statement?
- How to Fetch values from WP database based on selected option value by onchange using PHP?
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- How to create a custom category of wordpress admin
- WordPress automatically adding html tag around PHP code
- WordPress child theme fails to override parent navigation menu in /inc/structure/header.php
- Customizer: Output default value in Customizer CSS
- Converting HTML Template to WordPress Theme
- Prev/Next child navigation for current page modifications?
- Adding rel tag to all external links
- PHP Warning: chmod(): Operation not permitted in class-wp-filesystem-direct.php on line 173
- Saving an array of dynamic repeater data as post_meta
- WordPress asks you for your FTP details if you want to run Automatic Updates/Upgrade Plugins
- Show success or error messages in Ajax response to WordPress custom registration form
- How to add a Custom Mailchimp AJAX Newsletter Subscribe Form
- 404 error when I acess the second page of post-type
- Where can I create a normal php file?
- Trying do build a contact form
- How to Disable WordPress Page Revisions?
- Prev/Next Links Broken on Static Front Page Pagination
- How to integrate noimage picture in this code
- get comment data using comment id
- How to add no follow to specific links?
- WordPress transient not working with WP Engine
- Basic wpdb update question
- Only show size attributes in product box woocommerce when available
- Can I set up a hover animation in CSS depending on a PHP conditional?
- WP check_ajax_referer() is not working
- Remove conditional tag from header
- WordPress upload file size error even after raising php limits
- Function for simple math doesn’t work what am I doing wrong? [closed]
- Will I have problem with PHP 5.5 and WordPress 4.9.4?
- Disable Content Editor for Specific Pages
- How do i wrap woocomerce attribute in list?
- Removing files programmatically
- Trying to run website a php file is blank
- Php code error in wordpress if else statements [closed]
- How to access all meta data for RSS feed?
- Why Is Number of views on wordpress single post wrong?
- Create condition for Author bio Social Links
- How do I Populate a Table Field with User Meta Data?
- Redirecting visitor from foreign domain with WP content as referrer
- add another variable to php function
- How to remove get_header From all single pages in wordpress with functions.php without plugin?
- wp_query – Exclude the first thumbnail from lazy loading on archives
- How do I select two meta_value by $ wpdb-> get_row mode?
- Change lost password url to a mailto URL in WordPress
- Usermeta data unserialize, extract and display in table in WordPress
- Exclude category from woocommerce product category list
- Send POST request to Flask app from functions.php file
- How to use a variable (for wordpress postid) in other queries?
- How to let mobile navigation menu close when link is clicked?
- How to transfer variables from one function to another [closed]
- Displaying SQL query result from user input via wpdb
- Display specific page if user signed in
- Encoding video without exec function
- wordpress method GET adress bar rewrite
- wordpress dependent dropdownlist using post type is not working
- Show products per shortcode
- How to insert text into post based on category – via single.php file
- How to add Open/Close Toggle button into Twenty Fifteen theme for hiding left sidebar?
- Update user_email via php – WP 4.7
- str_replace not preserving whitespace
- redirect 301 with special character like WIX site “#!”
- customizer live preview layout picker
- Display tab title as ‘blog tagline | blog title’
- Conditional statement within WP SQL query
- Modify category archive page loop on functions.php
- How to display html code on homepage
- two wordpress sites, two themes, one database, same content
- Check if values exists DB
- Trying to exclude posts from a category on the home page
- Php conditional help needed
- Adapting a php array to WordPress
- Different layout on search page depending on category post
- Dynamically pull the correct email address from a match
- How to quickly/easily make an analysis (reverse engineering) of WordPress?
- New to wordpress. Need Help with templates [closed]
- Issues trying to add a href statment with PHP into a PHP Echo Statement [closed]
- Help with if/else loop [closed]
- Alternative to php echo within code
- Add multiple HTML attributes to an Elementor button
- Why does WordPress not send the user the email to add a password?
- How to put a class in the p tag automatically added by the_content() in the wordpress loop?
- How to sort custom sortable column by custom table value