How can I create a plugin that changes the title color of a website?

admin2025-06-05  2

I'm new to building plugins and just for testing purposes I would like to build a simple plugin that changes the title of website. What hooks or filter would I need?

I'm new to building plugins and just for testing purposes I would like to build a simple plugin that changes the title of website. What hooks or filter would I need?

Share Improve this question edited Dec 14, 2018 at 20:29 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Dec 14, 2018 at 2:26 Brian hernandezBrian hernandez 132 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

The exact way to do this may vary based on the theme you are using, but here's a simple plugin that hooks into the wp_head action hook and adds some style to the header:

<?php
/**
 * @package PACKAGE_NAME
 */
/*
Plugin Name: Plugin name
Plugin URI: https://plugin-website
Description: Plugin Description
Version: 1.0.0
Author: Plugin Author
Author URI: https://author-website
License: Plugin License
Text Domain: text-domain
*/

add_action( 'wp_head', 'wpse321903_add_styles' );

function wpse321903_add_styles(){ ?>
    <style>
        .page-title {
            color: white;
        }
    </style><?php
}

Or, if you are already enqueuing your stylesheet ( as you should be ), you can use wp_add_inline_style(). Set-up your plugin header as explained by Jack, and use this code below instead:-

// if your plugin has its own stylesheet, include this line
// replacing 'my-plugin-css.css' for your stylesheet filename

wp_enqueue_style( 'my-plugin-css', 'my-plugin-css.css' );


// add the inline style
// if you want to hijack the themes style, leave out the line above
// and replace 'my-plugin-css' with your theme's wp_enqueue_style handle.

$custom_css = "
.page-title {
    color: #f00;
}";
wp_add_inline_style( 'my-plugin-css', $custom_css );

See here for more details: https://codex.wordpress/Function_Reference/wp_add_inline_style

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749098343a316347.html

最新回复(0)