Git Product home page Git Product logo

Comments (3)

msaari avatar msaari commented on August 18, 2024 1

I now had time to look at this. Yes, the inline styles can be changed to use wp_add_inline_style(), and that will be implemented in the next version. Thanks!

from relevanssi.

msaari avatar msaari commented on August 18, 2024

The inline <script> tag – no problem, I've fixed that (for WP 5.7+ users).

The inline styles in the related posts are a trickier case to solve. The styles are related to a template, which may or may not be loaded. Adding a CSS file loaded when the template is used is possible, but it seems somewhat complicated. Also, part of the CSS depends on the user settings. wp_add_inline_style() requires a stylesheet where the inline style is added, and Relevanssi Premium has no stylesheet in itself, so that's not an option.

At the moment, I think this can be left as is. The current solution is convenient for most users, and if you need to avoid inline styles, it's easy to create a version of the template without the inline CSS and simply place the CSS in your theme stylesheet.

from relevanssi.

huubl avatar huubl commented on August 18, 2024

Hi @msaari

Thanks for your reply and willing to change the inline <script> tags. For inline styles this could be a solution:

function add_inline_styles() {
	$custom_css = "
		body {
			background-color: #ff0000;
		}
	";

	$handle = 'custom-inline-styles';

	wp_register_style( $handle, false ); 

	wp_add_inline_style( $handle, $custom_css );

	wp_enqueue_style( $handle );
}
add_action('wp_enqueue_scripts',  'add_inline_styles');

Registering a stylesheet without src (set to false) is possible and valid and Wordpress core is using this too. Using wp_add_inline_style makes it more easy to add a nonce.

from relevanssi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.