How to Add Code to WordPress (Easy and Safe)

woologgerDoğrulanmış Hesap
|
20.09.2024
|
|
534
WordPress te Ozel Kod Parcaciklari Ekleme wpcode 1

Sayfa İçerisindeki Konu Başlıkları

  • ● Adding Custom Code Snippets in WordPress

Adding Custom Code Snippets in WordPress

First, you need to install and activate the free WPCode plugin on your website.

After activation, the plugin will add a new menu item labeled ‘Code Snippets’ to your WordPress admin bar. Click this and you will see a list of all the custom code snippets you have saved on your site.

Since you just installed the plugin, your list will be empty.

Click the ‘Add New’ button to add your first custom snippet to WordPress.

WordPress te Ozel Kod Parcaciklari Ekleme wpcode 5

This will bring you to the ‘Add Snippet’ page. Here you can choose a snippet from the pre-made library or add your own custom code.

To add custom code, click on the ‘Use Snippet’ button under the ‘Add Your Custom Code (New Snippet)’ option.

WordPress te Ozel Kod Parcaciklari Ekleme wpcode 4

You need to start by entering a title for your custom code snippet. This can be anything that will help you identify the code.

Then you can copy and paste your snippet into the Code Preview box. Make sure you select the right code type from the drop-down menu on the right.

WordPress te Ozel Kod Parcaciklari Ekleme wpcode 3 1536x587

In the screenshot above, we have added a custom code snippet to remove WordPress Google Fonts from our test site.

/** Remove loading gfonts */
add_filter( 'style_loader_src', function( $href ) {
    if( strpos( $href , "//fonts.googleapis.com/" ) === false ) {
        return $href;
    }
    return false;
});
 
// Remove dns-prefetch for fonts.googleapis
add_filter( 'wp_resource_hints', function( $urls ) {
 
    foreach ($urls as $key => $url) {
        if ( 'fonts.googleapis.com' === $url ) {
            unset( $urls[ $key ] );
        }
    }
    return $urls;
} );

When you have finished setting the options, toggle the switch in the top right corner from ‘Inactive’ to ‘Enabled’ and then click on the ‘Save Particle’ button.

WordPress te Ozel Kod Parcaciklari Ekleme wpcode 2

If you want to save the snippet and not activate it, just click on the ‘Save Snippet’ button.

Once you save and activate the snippet, it will be automatically added to your site or displayed as a shortcode, depending on the embedding method you choose.

Leave a Comment

Puanınız:*

1000