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?
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