Advertisement

Spotlight Backed and Nofollow Hyperlinks in Gutenberg

wordpress-highlight-nofollow-sponsored-links-scaled-1.webp” alt=”” title=”wordpress-highlight-nofollow-sponsored-links-scaled-1″ srcset=”https://wpmountain.com/wp-content/uploads/2024/09/wordpress-highlight-nofollow-sponsored-links-scaled-1.webp 1920w, https://wpmountain.com/wp-content/uploads/2024/09/wordpress-highlight-nofollow-sponsored-links-scaled-1-1280×509.webp 1280w, https://wpmountain.com/wp-content/uploads/2024/09/wordpress-highlight-nofollow-sponsored-links-scaled-1-980×389.webp 980w, https://wpmountain.com/wp-content/uploads/2024/09/wordpress-highlight-nofollow-sponsored-links-scaled-1-480×191.webp 480w” sizes=”(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) and (max-width: 1280px) 1280px, (min-width: 1281px) 1920px, 100vw” class=”wp-image-197416″/> I have simply gone through outdated articles over the past few years and updated the text affiliate links (affiliate links) next […]

I have simply gone through outdated articles over the past few years and updated the text affiliate links (affiliate links) next to any affiliate links for full disclosure. I have also changed links that were previously using rel nofollow to backed.

This is a long process, because we have been given a lot of posts and I am completely revamping the look of our theme and plugin collections. To simplify the issues, I added some code to the Internet web page that will highlight backed and nofollow links, so I can find them quickly.

I’m not the only one who could benefit from highlighting backed/rel links, so I thought I’d share some knowledge on how I did it. Being able to quickly look at a submission and see the links will help you judge if there are too many and if you should remove some. It will also help you see which links don’t have any rel functionality, so you can decide if you need to add one or not.

<h2 class=”wp-block-heading” id=”h-how-to-add-css-to-the-wordpress-editor”>Learn how to add CSS to the wordpress editor

To highlight links, we’ll want to add some CSS to the wordpress editor. If you’re working with a theme, you can simply add custom CSS to the editor using a css record, otherwise you can insert inline CSS with a hook.

Using an editor CSS record:

Simply create a brand new style-editor.css record for your theme and add the following:

add_action( 'after_setup_theme', function() {
    add_theme_support( 'editor-styles' );
    add_editor_style( 'style-editor.css' );
} );

wordpress will then automatically load this record into all text and block editors.

Along with inline CSS:

You will need to if you are not working with a theme, you will still be able to add CSS to the inline editor. For this you will hook into the enqueue_block_editor_assets hook

/**
 * Hooks into "enqueue_block_editor_assets" as a way to upload inline sorts to the Gutenberg Editor.
 */
add_action( 'enqueue_block_editor_assets', function() {
	wp_register_style( 'wpexplorer-editor-styles', false );
	$css="YOUR CSS HERE";
	wp_add_inline_style( 'wpexplorer-editor-styles', $css );
	wp_enqueue_style( 'wpexplorer-editor-styles' );
} );

For the purpose of this data, I will use the second method. It is because I will be able to place my code inside a plugin, so I will simply allow/disable the aptitude.

Highlighting inline links with their rel function is very easy! We will simply use the tilde CSS feature selector. In case you are not familiar with feature selectors, I recommend you take a look at w3schools. Here is an example of the CSS we can use:

a[rel~=sponsored], a[rel~=nofollow] {
    background: #FFFF00;
    color: #000;
}

This CSS will make any link that has a rel backed or nofollow functionality appear Like this.

Now, since we are working with the wordpress editor, it is a good idea to focus on .editor-styles-wrapper class name.

Centered on the editor-styles-wrapper the element is not required if you use the editor-styles method and load a css record via the child theme or if you are directed to the old editor. On the other hand it does not hurt to add it easily.

This is the updated CSS:

.editor-styles-wrapper a:is([rel~=sponsored],[rel~=nofollow]) {
    background: #FFFF00;
    color: #000;
}

In case you are using a editor-style.css record just add the code in there and save it. Another way you will be able to use the following function to insert this code inline:

/**
 * Supplies inline CSS to the block editor.
 */
add_action( 'enqueue_block_editor_assets', function() {
	wp_register_style( 'wpexplorer-editor-highlight-rel-sponsored-nofollow', false );
	wp_add_inline_style(
		'wpexplorer-editor-highlight-rel-sponsored-nofollow',
		'.editor-styles-wrapper a:is([rel~=sponsored],[rel~=nofollow]){background:#FFFF00;color: #000;}'
	);
	wp_enqueue_style( 'wpexplorer-editor-highlight-rel-sponsored-nofollow' );
} );

Result:

With this code added in case you need to edit any submissions that have nofollow or backed links, they will be highlighted so you can easily find them. Here is a screenshot from our wordpress Webhosting web page which does have affiliate links anyway:

<img decoding=”async” width=”2560″ height=”1017″ src=”https://wpmountain.com/wp-content/uploads/2024/09/wordpress-highlight-nofollow-sponsored-links-scaled-1.webp” alt=”” class=”wp-image-65145″/>

Now I’m just going to scan everywhere for nofollow and backed links! You’ll actually be able to use this concept for various problems (not sure what it could be…let me know in the comments).

Download the Plugin

I have created a little plugin that has the code for this data if you just want to download it and upload it to your internet web page. You will be able to go check out the plugin on Github.

The reason I don’t upload those mini plugins to the wordpress.org checklist is because the review process is also complete shit. It takes a month just to get your plugin reviewed. I don’t understand why with the amount of money wordpress makes, they can’t just hire more reviewers.

Let me know in the comments if this plugin was useful to you or if you have any questions!

Spotlight Submission Backed & Nofollow Hyperlinks in Gutenberg appeared first on WPExplorer.

WP Support Plans

[ continue ]

wordpress Maintenance Plans | wordpress hosting

Learn more

Source link

See what others are saying about this...

Methods for salary negotiation before joining a company

Before you even imagine having to negotiate salary in every single interview, the most important thing is to take the opportunity to be productive. Timing is much more important than the negotiation process itself.and it is also decided through the availability...

[Free WPBeginner Workshop] Discover the secret to growing your email list quickly!

Want to know how savvy executives grow their email lists? Have you ever tried, if necessary, to learn all the tricks shown for email promotion and advertising and the ways in which you can get results WITHOUT spending hours on trial and error? Then I have great...

Are Mikoh swimsuits & dresses (Resort!) ideal for a young woman?

    YES!  Mikoh swimsuites & dresses, in the Resort styles & designs are ideal for women of all ages, especially younger women! Mikoh Resort: Mikoh offers a stunning array of resort wear, from breezy cover-ups to chic jumpsuits, perfect for lounging by the...

How WordPress Monitoring Prevents Downtime: A Complete Guide WordPress is…

wordpress-monitoring-prevents-downtime-a-comprehensive-guide-wordpress-is_199339.jpg” alt=”” title=”How wordpress Monitoring Prevents Downtime: A Comprehensive Guide wordpress is…”...

Soulmate Test: Find Your Soulmate and Twin Flame

Product Name: Soulmate Test: Find Your Soulmate and Twin Flame Click here to get Soulmate Test: Find Your Soulmate and Twin Flame at discounted price while it’s still available… All orders are protected by SSL encryption – the highest industry...

– Goodbye keto

Product Name: – Goodbye keto Click here to get – Goodbye keto at discounted price while it’s still available… All orders are protected by SSL encryption – the highest industry standard for online security from trusted vendors. –...

TruVarin – Enriched formula for hair growth

Product Name: TruVarin – Enriched formula for hair growth Click here to get TruVarin – Enriched formula for hair growth at discounted price while it’s still available… All orders are protected by SSL encryption – the highest industry...

Friends with benefits

Product Name: Friends with benefits Click here to get Friends with benefits at discounted price while it’s still available… All orders are protected by SSL encryption – the highest industry standard for online security from trusted vendors. Friends...

Unlock my spine

Product Name: Unlock my spine Click here to get Unlock my spine at discounted price while it’s still available… All orders are protected by SSL encryption – the highest industry standard for online security from trusted vendors. Unlock my spine is...

Production Scheduling Template – Production Scheduling in Excel Spreadsheet for Master Scheduler

Product Name: Production Scheduling Template – Production Scheduling in Excel Spreadsheet for Master Scheduler Click here to get Production Scheduling Template – Production Scheduling in Excel Spreadsheet for Master Scheduler at discounted price while...

Spotlight Backed and Nofollow Hyperlinks in Gutenberg

wordpress-highlight-nofollow-sponsored-links-scaled-1.webp” alt=”” title=”wordpress-highlight-nofollow-sponsored-links-scaled-1″ srcset=”https://wpmountain.com/wp-content/uploads/2024/09/wordpress-highlight-nofollow-sponsored-links-scaled-1.webp 1920w, https://wpmountain.com/wp-content/uploads/2024/09/wordpress-highlight-nofollow-sponsored-links-scaled-1-1280×509.webp 1280w, https://wpmountain.com/wp-content/uploads/2024/09/wordpress-highlight-nofollow-sponsored-links-scaled-1-980×389.webp 980w, https://wpmountain.com/wp-content/uploads/2024/09/wordpress-highlight-nofollow-sponsored-links-scaled-1-480×191.webp 480w” sizes=”(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) and (max-width: 1280px) 1280px, (min-width: 1281px) 1920px, 100vw” class=”wp-image-197416″/> I have simply gone through outdated articles over the past…