Community Forums › Forums › Archived Forums › Design Tips and Tricks › Allow HTML tags in text field
Tagged: html tags
- This topic has 6 replies, 2 voices, and was last updated 5 years, 11 months ago by MalinD.
-
AuthorPosts
-
May 30, 2018 at 4:59 am #220378MalinDParticipant
Hi
I am working on a child theme for Genesis and have created some functions in the customizer.php. I now try to allow html tags to be displayed but have not succeeded. I found a lot of ideas but non of them have worked out.Just in this case I want the html tags to be displayed on the front page (front-page.php).
Anyone who knows how to solve this problem?
Regards Malin
May 30, 2018 at 8:34 pm #220404Brad DaltonParticipantMay 31, 2018 at 12:45 am #220407MalinDParticipantIn the header I have a background image with a headline, text and a button.
I would like to be able to add a breakline (<br>) and other tags in the text and headline.
But this are ignored/disappearing when saving, so I belive that I have to add some code in the customizer.php to prevent that. I am not sure... Maybe something in the code at the front-page.php as well.May 31, 2018 at 12:56 am #220408Brad DaltonParticipantI assume you mean the site header? You can use this code to filter the site title and add HTML tags https://my.studiopress.com/documentation/snippets/header/modify-the-header-url/
You could also use the genesis_header hook or a filter hook for the header image.
May 31, 2018 at 1:24 am #220409MalinDParticipantThat was an interesting article, I will save this for later! Thank you
I am sorry, but I think I have explained the problem porly... I don't think I can use this for my problem.In customizer.php I have added some sections, settings and controls. In this case I created a few text fields that the user could fill in to display the text and headline (Appearance/Customize/Header Section).
When filling in this text field the tags are disappearing when saving.
So what I have to do it allow html tags in the text field and to display them on the front page (or other places)May 31, 2018 at 4:26 am #220416Brad DaltonParticipantIf you look in the Academy Pro customize.php file you'll find the code which allows HTML tags for the top banner.
// Top banner section. $wp_customize->add_section( 'academy-top-banner-settings', array( 'description' => sprintf( '%s<p>%s</p>', __( 'Modify the settings for the top banner section.', 'academy-pro' ), __( 'Each time the customizer is opened, the top banner will be displayed in the live preview so you can easily customize the content.', 'academy-pro' ) ), 'title' => __( 'Top Banner Settings', 'academy-pro' ), 'panel' => 'academy-settings', ) ); // Top banner visibility. $wp_customize->add_setting( 'academy-top-banner-visibility', array( 'default' => 1, 'sanitize_callback' => 'absint' ) ); $wp_customize->add_control( 'academy-top-banner-visibility', array( 'description' => __( 'Check the box to display a dismissible banner at the top of all pages.', 'academy-pro' ), 'label' => __( 'Show Top Banner?', 'academy-pro' ), 'section' => 'academy-top-banner-settings', 'settings' => 'academy-top-banner-visibility', 'type' => 'checkbox', ) ); // Hero banner text. $wp_customize->add_setting( 'academy-top-banner-text', array( 'default' => academy_get_default_top_banner_text(), 'sanitize_callback' => 'wp_kses_post', 'transport' => isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh', ) ); $wp_customize->add_control( 'academy-top-banner-text', array( 'description' => __( 'Change the text for the dismissible banner (allows HTML).', 'academy-pro' ), 'label' => __( 'Top Banner Text', 'academy-pro' ), 'section' => 'academy-top-banner-settings', 'settings' => 'academy-top-banner-text', 'type' => 'textarea', ) ); if ( isset( $wp_customize->selective_refresh ) ) { $wp_customize->selective_refresh->add_partial( 'academy-top-banner-text', array( 'selector' => '.academy-top-banner', 'settings' => array( 'academy-top-banner-text' ), 'render_callback' => function() { return get_theme_mod( 'academy-top-banner-text' ); } ) ); }
And then output like this :
add_action( 'genesis_before', 'academy_do_top_banner' ); function academy_do_top_banner() { if ( get_theme_mod( 'academy-top-banner-visibility', true ) ) { printf( '<div class="academy-top-banner">%s</div>', get_theme_mod( 'academy-top-banner-text', academy_get_default_top_banner_text() ) ); } }
May 31, 2018 at 6:19 am #220419MalinDParticipantHi and a big big thank you!!
It was the callback function in customizer.php that did the trick, I already had get_theme_mod in the front-page-file.Now it works like a charm!
Thank you for taking your time and for solving this 🙂 -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.