0

I have this code in a simple plugin that is supposed to make wordpress unbranded:

<?php 

/*
* Class to remove wp-* branding from WordPress
* @package users-manager.php
*/

class WpUnbrand {

    public function __construct()
    {
        add_action('wp_head', array($this, 'remove_wp_header_links'));
        add_action('init', array($this, 'remove_wp_default_jquery'));
    }

    public function remove_wp_header_links()
    {
        remove_action('wp_head', 'rsd_link');
        remove_action('wp_head', 'wp_generator');
        remove_action('wp_head', 'feed_links', 2);
        remove_action('wp_head', 'index_rel_link');
        remove_action('wp_head', 'wlwmanifest_link');
        remove_action('wp_head', 'feed_links_extra', 3);
        remove_action('wp_head', 'start_post_rel_link', 10, 0);
        remove_action('wp_head', 'parent_post_rel_link', 10, 0);
        remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);
    }

    public function remove_wp_default_jquery()
    {
        if( !is_admin() ){
            wp_deregister_script('jQuery');
            wp_register_script( 'jQuery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js', false, false);
            wp_enqueue_script( 'jQuery' );
        }
    }

}

new WpUnbrand();

?>

At the moment the plugin is in development so I didn't added the needed headers and I'm calling it inside another plugin like a component of the other plugin. I want to make is an indipendent plugin, but I've noticed that the wp_head isn't called. Is there something wrong into the code?

1 Answer 1

0

If it is your actual code, you have hook to wp_head commented:

//add_action('wp_head', array($this, 'remove_wp_header_links'));

Just remove slashes and it should work.

add_action('wp_head', array($this, 'remove_wp_header_links'));
3
  • I've commented the hook to continue the plugin development. Also if it's uncommented, it will be not fired and inspecting using chrome console will show me into the <head> tag all the stuff that wordpèress will add
    – ICTDEV
    Oct 6 at 7:50
  • Did you try to change priority? You can't remove actions that wasn't created before. So you can try for example this call: add_action('wp_head', array($this, 'remove_wp_header_links'), 20); To be sure your function will be called later.
    – mWin
    Oct 9 at 17:47
  • need to test, not tried to give a major priority. I'll let you know. Thanks
    – ICTDEV
    Oct 10 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.