$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>How can I create a plugin that changes the title color of a website?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin11PV0评论

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

Post a comment

comment list (0)

  1. No comments so far