admin管理员组文章数量:1130349
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 badges2 Answers
Reset to default 1The 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
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 badges2 Answers
Reset to default 1The 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
本文标签: How can I create a plugin that changes the title color of a website
版权声明:本文标题:How can I create a plugin that changes the title color of a website? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749098318a2315606.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论