简体   繁体   中英

Add Custom CSS in Wordpress With Plugin

I Am Creating Wordpress Plugin for help people for protect their content from being Copy. There are many Plugins to protect Content from Being Copy when JS is on, but no plugin is there which protect content even when javascript is off. I want to add this Custom CSS Code in PHP file, for protect content copy via CSS

body {
    user-select: none;
    -moz-user-select: none;
    -webkit-user-select: none;
    -o-user-select: none;
}

How to add this custom css code in php file for protect content? and then install that php file as wordpress plugin. PS - I don't have much knowledge in Coding so asked here, any help will be appriciated. Thanks

By using following code block, you can enqueue your css stylesheet :
The following code have to be in functions.php file.
You have to have

wp_head() just before closing head tag in header.php file.

function add_style_to_your_page() {
wp_enqueue_style( 'custom-css-name', get_template_directory_uri(). '/path-to/custom.css' );
add_action( 'wp_enqueue_scripts', 'add_style_to_your_page' );

The above code links to your external css file.

Also I think the you can enqueue your style sheet in the plugin-name.php file .

With wp_head() before closing head tag in header.php file .

For more reference https://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts and https://developer.wordpress.org/reference/functions/wp_enqueue_script/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM