Updated on 13 Feb 2024
One of the most annoying defaults in Bricks is the div tag that gets applied to the output of Basic Text elements.
<div id="brxe-qgttsu" class="brxe-text-basic">Here goes your text ... Select any part of your text to access the formatting toolbar.</div>
It is certainly possible to select p
from the select dropdown menu and go on with your life.
The easiest way to change the default HTML tag from div to p for new elements going forward is using Advanced Themer.
If you do not want to use Advanced Themer (not sure why one wouldn’t!), here’s one way in which the same can be done: Copy the default element over to the child theme and modify it.
This tutorial shows how.
Step 1
Install and activate the Bricks child theme if you haven’t already.
This can be done at any time and not just when you are about to begin working on a site. Your site won’t be affected.
Step 2
Copy
/wp-content/themes/bricks/includes/elements/text-basic.php
to
/wp-content/themes/bricks-child/elements
Step 3
Edit the above file at /wp-content/themes/bricks-child/elements/text-basic.php.
a) Near the top of the file, comment out or delete
namespace Bricks;
b) Change
class Element_Text_Basic extends Element {
to
class Element_Text_Basic extends \Bricks\Element {
c) Inside set_controls()
change
$this->controls['tag'] = [
'tab' => 'content',
'label' => esc_html__( 'HTML tag', 'bricks' ),
'type' => 'select',
'options' => [
'div' => 'div',
'p' => 'p',
'span' => 'span',
'figcaption' => 'figcaption',
'address' => 'address',
'figure' => 'figure',
'custom' => esc_html__( 'Custom', 'bricks' ),
],
'lowercase' => true,
'inline' => true,
'placeholder' => 'div',
];
to
$this->controls['tag'] = [
'tab' => 'content',
'label' => esc_html__( 'HTML tag', 'bricks' ),
'type' => 'select',
'options' => [
'div' => 'div',
'p' => 'p',
'span' => 'span',
'figcaption' => 'figcaption',
'address' => 'address',
'figure' => 'figure',
'custom' => esc_html__( 'Custom', 'bricks' ),
],
'lowercase' => true,
'inline' => true,
'placeholder' => 'p',
'default' => 'p',
];
d) Change
Helpers
to
\Bricks\Helpers
Step 4
Edit child theme’s functions.php
.
Change
/**
* Register custom elements
*/
add_action( 'init', function() {
$element_files = [
__DIR__ . '/elements/title.php',
];
foreach ( $element_files as $file ) {
\Bricks\Elements::register_element( $file );
}
}, 11 );
to
/**
* Register custom elements
*/
add_action( 'init', function() {
$element_files = [
__DIR__ . '/elements/text-basic.php',
];
foreach ( $element_files as $file ) {
\Bricks\Elements::register_element( $file );
}
}, 11 );
and you are done.
Now when a Basic Text element is added:
<p id="brxe-ctzttq" class="brxe-text-basic">Here goes your text ... Select any part of your text to access the formatting toolbar.</p>
All is well in the world again.
3 comments
kostas
It works perfectly until I add a word limit. Something like
" Fatal error: Uncaught Error: Class "Helpers" not found in -
\public\wp-content\themes\bricks-child\elements\text-basic.php:93 Stack trace: #0 "
Sridhar Katakam
Updated the tutorial per https://www.facebook.com/groups/brickscommunity/posts/1317946128869904/?comment_id=1318319258832591&reply_comment_id=1318389725492211.
Jan
Thanks for the tutorial. Works! 🙂