Nicolas Langle
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Add color reference to css that alters with a new theme….Hebhansen,
1 – You can create a child theme with a theme.json file in it. Both files will be merged. Or you can create a style variation by creating a styles folder at the root of your theme. It depends of your needs.
2 – SCSS has been created to give extra fonctionnalites to developers such as mixins, variables, functions… Browsers can’t interpretate it. You need what we call a transpiler. A transpiler convert a language to an other, it’s a development tool, it is not used in production. In our case you need a transpiler which convert SCSS to CSS.
3 – As I understand your demand, you want to easily override colors of plugins you often use ? But you can’t do that with SCSS. You can override CSS variables if your plugins use somes. As I see it, the more easy way to do what you want it to recreate a css file and override rules
my-file.css:root {
--my-color: #000;
}
.wp-forms-form .wpforms-field-label {
color: var(--my-color);
}
#tinymce {
color: var(--my-color);
}
...Best regards.
Forum: Developing with WordPress
In reply to: Add color reference to css that alters with a new theme….Yes, they exist in default themes. It’s a behavior of the new FSE system via a theme.json file or/and styles variations. You can take a look at the documentation here.
And more precisely by this part which explains how to configure colors.
Then you will be able to use or override the WordPress css variables :
--wp--preser--color--<your color name>
- This reply was modified 1 month, 2 weeks ago by Nicolas Langle.
Forum: Developing with WordPress
In reply to: Add color reference to css that alters with a new theme….Forum: Developing with WordPress
In reply to: Add pagination number on a specific pageHi Marseem,
If your videos are all on the same page you can use the Gutenberg page break block.
Best regards
You’re welcome, thank for your feed back !
Sorry, I should have elaborated a little. I haven’t tried, but I think something like this should work :
<html>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<?php
$block_header_part = get_block_template( get_stylesheet() . '//header', 'wp_template_part' );
$block_header = $block_header_part && ! empty( $block_header_part->content ) ? do_blocks( $block_header_part->content ) : '';
$block_content = do_blocks( '
<!-- wp:group {"layout":{"type":"constrained"}} -->
<div class="wp-block-group">
<!-- wp:post-content /-->
</div>
<!-- /wp:group -->'
);
?>
<?php wp_head(); ?>
</head>
<body>
<?php
echo $block_header;
echo $block_content;
?>
</body>
</html>Can you test that and tell me if it’s work ?
- This reply was modified 4 months, 3 weeks ago by Nicolas Langle.
Hi @dahliasan,
This two functions do the same thing,
block_header_area
call the functionblock_template_part
which call the functiondo_blocks
function block_header_area() {
block_template_part( 'header' );
}function block_template_part( $part ) {
$template_part = get_block_template( get_stylesheet() . '//' . $part, 'wp_template_part' );
if ( ! $template_part || empty( $template_part->content ) ) {
return;
}
echo do_blocks( $template_part->content );
}- This reply was modified 4 months, 3 weeks ago by Nicolas Langle.
Good to know, thank you for the feed back !
I have tested something witch seems to work, but you will not be able to compile scss, you will have to use plain css or create your own stack :
build/
├─ block1/
│ ├─ block.json
│ ├─ index.js
├─ block2/
│ ├─ block.json
│ ├─ index.js
common
├─ stlye.css
src/
├─ ...In block.json file :
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "block/name",
"version": "1.0.0",
...
"style": "file:../../common/style.css"
}- This reply was modified 4 months, 3 weeks ago by Nicolas Langle.
Hum, Gutenberg doesn’t work this way so each block should be able to load its own css when needen. It’s how the create-block stack is build so I don’t think there is a way to do what you want.
If you have shared style between block maybe you can create separate css file but you will have to enqueue it manually both in frontend and in editor.
build/
├─ blocks/
│ ├─ block1/
│ │ ├─ block.json
│ │ ├─ index.css
│ │ ├─ style-index.css
│ ├─ block2/
│ │ ├─ block.json
│ │ ├─ index.css
│ │ ├─ style-index.css
src/
├─...
common/
├─ style.css
├─ editor.css
my-block-plugin.phpIn the php file, something like that :
if ( is_admin() ) {
add_action( 'init', function() {
add_editor_style( $editor_css_path );
} )
}
if ( ! is_admin() ) {
add_action( 'wp_print_styles', function() {
wp_enqueue_style( 'my-block-plugin', $style_css_src, ... )
} )
}But this way, you lose the ability of Gutenberg to load style on frontend only when your blocks are present in the page.
Sorry I don’t see any other possibilities… Hope this help
- This reply was modified 4 months, 3 weeks ago by Nicolas Langle.
Hi @hannnes,
You can convert your css file into scss and then import your style (for the frontend) inside the edit file (for the backend) :
// edit.scss
@import './style.scss';Like that, you have the frontend style in the editor and you can add additional rules for the backend
Is that you want to do ?
Forum: Fixing WordPress
In reply to: Page retrieval time from googleGoogle crawl the same page as user, improve speed for user also improve speed for google crawler
Forum: Fixing WordPress
In reply to: Page retrieval time from googleHi @eliot1988,
Your speed is good on desktop but the score is less good on mobile, you can check that here :
https://pagespeed.web.dev/analysis/http-metalstories-gr/y1eqzlomrl?hl=fr&form_factor=mobile
You can try Wp rocket to improve your site performances if you have not already installed it :
Forum: Developing with WordPress
In reply to: Get file size, dimension and file type in image captionIf you use Gutenberg editor for displaying your image, something like that should work :
/**
* Get file details string
* @param int $id
* @return string
*/
function get_file_details_string( $id ) {
$file_path = get_attached_file( $id );
if ( empty( $file_path ) ) {
return '';
}
$file_weight = size_format( wp_filesize( $file_path ) );
$file_size = wp_getimagesize( $file_path );
return '<strong>File Type:</strong> ' . $file_size['mime'] . ' | <strong>File Size:</strong> ' . $file_weight . ' | <strong>Dimensions:</strong> ' . $file_size[0] . ' x ' . $file_size[1] . ' pixels';
}
/**
* Override block core image render
* @param string $block_content
* @param array $block
* @param WP_Block $instance
* @return string
*/
function override_block_core_image_render( $block_content, $block, $instance ) {
if ( empty( $block['attrs']['id'] ) ) {
return $block_content;
}
$file_details = get_file_details_string( $block['attrs']['id'] );
if ( str_contains( $block_content, '</figcaption>' ) ) {
return str_replace( '</figcaption>', '<br />' . $file_details . '</figcaption>', $block_content );
}
return str_replace( '</figure>', '<figcpation>' . $file_details . '</figcpation></figure>', $block_content );
}
add_filter( 'render_block_core/image', 'override_block_core_image_render', 20, 3 );you have to put that in your PHP functions file and then use an image block in Gutenberg editor in order to view the result
Best regards
- This reply was modified 4 months, 4 weeks ago by Nicolas Langle.
- This reply was modified 4 months, 4 weeks ago by Nicolas Langle.
- This reply was modified 4 months, 4 weeks ago by Nicolas Langle.
- This reply was modified 4 months, 4 weeks ago by Steven Stern (sterndata).