CSS properties in textarea in the Customizer

I am trying to create a custom field (text/CSS code in textarea) that include the CSS suggestion like Additional CSS in the customizer:
https://i.postimg.cc/9QhLPgVk/image.png.

Does everybody has experience with that?

I need any solution like the above screenshot here: https://i.postimg.cc/L55cpChD/image.png.

theme customizer – Widget Modification

I want to modify a tiny aspect of a widget I currently use, it came with the theme or perhaps the recommended theme toolkit plugin… not sure which.

The widget displays featured pages on the homepage but I’d prefer it to display category instead or the option of both with the same design and style.

I figured I could modify it with the code but I can’t seem to find it.

Anyone know how I can go about fixing this?

I found the code from the parent theme’s function.php

”’
/**

  • Featured Section
    */
    function blossom_feminine_featured_section(){
    $ed_featured = get_theme_mod( ‘ed_featured_area’, true );
    $featured_page_one = get_theme_mod( ‘featured_content_one’ );
    $featured_page_two = get_theme_mod( ‘featured_content_two’ );
    $featured_page_three = get_theme_mod( ‘featured_content_three’ );
    $featured_pages = array( $featured_page_one, $featured_page_two, $featured_page_three );
    $featured_page = array_diff( array_unique( $featured_page), array( ” ) );

    if( is_home() && $ed_featured && $featured_pages ){
    $args = array(
    ‘post_type’ => ‘page’,
    ‘post_status’ => ‘publish’,
    ‘posts_per_page’ => -1,
    ‘post__in’ => $featured_pages,
    ‘orderby’ => ‘post__in’
    );
    ”’

sharepoint online – SPFx Application customizer and SPFx webpart connection

I know we can create connected SPFx webparts but is it possible to create the connection between SPFx application customizer and SPFx webpart? The scenario is that we need to create application customizer(kind of welcome message and some options like search, switch option etc) in the header of the page and on change event of the switch button we need to show different view of the webpart(Grid/List view)

Missing “Additional CSS” option in Customizer

Since upgrading to WordPress 5.7, the “Additional CSS” option seems to be missing in Customizer at Appearance -> Customize on various WordPress websites I look after with various different themes including Astra and GeneratePress.

I have updated the plugins and themes to the latest versions but this has not helped.

I realise I can add custom CSS via a plugin and possibly via a child theme but what happened to this option?

customizer postMessage transport doesn’t update in javascript

in the absence of any significant official documentation for javascript in wordpress, namely the wp object
I am having hard time applying postMessage customizer controls (despite all the assurances in the theme developement handbook that it’s easy to do and all you need is to copy/paste the boilerplates)
the PHP part of my code works fine with refresh transport type, for the sake of example I will put a very minimalist code

add_action('customize_register',function ($wp_customize) {
        $wp_customize->add_section('mysection',array(
                'title' => 'section'
            )
        );
        $wp_customize->add_setting('mysetting', array(
            'transport' => 'postMessage',
            'type' => 'theme_mod'
        ));
        $wp_customize->add_control('mysetting',array(
                'section' => 'mysection'
            )
        );
    }
);
add_action('customize_preview_init',function () {
        wp_enqueue_script('random_name', get_template_directory_uri() . '/script.js', array('jquery', 'customize-preview'));
    }
);

nothing happens when I change to postMessage transport, while my JS code is as follow:

( function( $ ) {
    wp.customize( 'mysetting', function( value ) {
        value.bind( function( to ) {
            $( '#myinput' ).val( to );
        } );
    } );    
} )( jQuery );

you can guess index.php has one line: <input id="myinput"> and I checked and made sure script.js was loaded in the page.
I am getting all the changes using: wp.customize( 'mysetting').get() in the console, but I need it to automatically update the preview as it should ! without me refreshing the screen or clicking publish.
thank you for your time.

theme customizer – How to remove html tags from output with json_encode in WordPress? I want to show only plain text

I’ve been on trial and error for a few days, researching a lot, but I can’t solve this problem.

objective: this function generates schema output for data structured in JSON.

the problem: the texts are being delivered with html <p> tags, n etc, and I think that Google is not integrating my structured FAQ data because of this.

Output example:

"@type": "Question",
                    "name": "<p>What are the best destinations for my trip?</p>n",

the solution: I need to remove the <p> and </p> tags and show only plain text.

I tried using strip_tags and it worked partially:
"name": "'.strip_tags(apply_filters('the_content', $faq('question'))).'",

partially because I was able to remove the tags with this “solution”, but in contrast the JSON became invalid because added blank space and line breaks. Validation error message from JSONLint:
Expecting ‘STRING’, ‘NUMBER’, ‘NULL’, ‘TRUE’, ‘FALSE’, ‘{‘, ‘(‘, got ‘undefined’

this is the complete function code:

     public function render_schema()
{
  $faqs = $this->render_faqs();
  
    if (!$faqs)
    {
        return;
    }
    $schema = '
    <script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "FAQPage",
        "mainEntity": (';

    $comma = '';

    foreach ($faqs as $faq)
      
    {
        $schema .= ' 
                ' . $comma . ' {
                    "@type": "Question",
                    "name": '.json_encode(apply_filters('the_content', $faq('question'))).',
                    
                    "acceptedAnswer": {
                        "@type": "Answer",
                        "text": ' . json_encode(apply_filters('the_content', $faq('reply'))) . '
                    }
                }
                ';

        $comma = ',';

    }
    $schema .= '
        )
    }
    </script>';

    return $schema;
}

Block template not being included in pages created in the customizer

I have a block template set up so that my custom block (built using ACF) is automatically added to the top of each new page:

function jmc_register_page_template() {
    $post_type_object = get_post_type_object( 'page' );
    $post_type_object->template = array(
        array( 
            'acf/block-introduction-with-background', 
            array(
                'data' => array(
                    'introduction-with-background' => '<p>Your introductory paragraph text here</p>'
                )
            )
        ),    
    );
}
add_action( 'init', 'jmc_register_page_template' );

This works fine when creating a page in the usual w.

Within the customizer > menus > (my menu) > ‘add items’ I have the option to ‘Add new page’. This creates a new page and adds it to my menu. However, when I edit a new page created in this way the custom block isn’t included.

Can anyone tell me why and help me to make sure the template is applied to pages created this way please?

directory – WordPress hosted on subfolder of domain causing customizer to constantly refresh and is requesting jquery from root domain

So I have wordpress installed in a subfolder of my domain: https://example.com/blog

To do this I am reverse proxying ngnix (main app) to apache (wordpress server) and everything is going great.

One weird problem I noticed though is when I go to the customizer it keeps refreshing constantly. It looks like its trying to request jquery from the root https://example.com even though:

Site Address (URL)
WordPress Address (URL)

Are both set to: https://example.com/blog

Any ideas?

sharepoint online – Add Handling page creation events in your SPFx application customizer, not sure how i need to join the code

I have the following inside my application customizer SPFX extension, the code is responsible to load custom CSS inside the home page:-

import { override } from '@microsoft/decorators';
import { Log } from '@microsoft/sp-core-library';
import {
  BaseApplicationCustomizer
} from '@microsoft/sp-application-base';
import { Dialog } from '@microsoft/sp-dialog';

import * as strings from 'HelloWorldApplicationCustomizerStrings';

const LOG_SOURCE: string = 'HelloWorldApplicationCustomizer';

/**
 * If your command set uses the ClientSideComponentProperties JSON input,
 * it will be deserialized into the BaseExtension.properties object.
 * You can define an interface to describe it.
 */
export interface IHelloWorldApplicationCustomizerProperties {
  // This is an example; replace with your own property
  cssurl: string;
  scripturl: string;
}

/** A Custom Action which can be run during execution of a Client Side Application */
export default class HelloWorldApplicationCustomizer
  extends BaseApplicationCustomizer<IHelloWorldApplicationCustomizerProperties> {

    @override

    public onInit(): Promise<void> {
      Log.info(LOG_SOURCE, `Initialized ${strings.Title}`);
  
      const cssUrl: string = this.properties.cssurl;
      this.context.application.navigatedEvent.add(this ,()=>{
      const scriptUrl: string = this.properties.scripturl;

      const url = window.location.href;
      if (cssUrl && 
      (url.toLowerCase()=="https://***.sharepoint.com/sites/customeroperations/sitepages/dashboard.aspx"
      ||
      url.toLowerCase()== "https://***.sharepoint.com/sites/customeroperations"
      ) )
      {
          // inject the style sheet
          const head: any = document.getElementsByTagName("head")(0) || document.documentElement;
          let customStyle: HTMLLinkElement = document.createElement("link");
          customStyle.href = cssUrl;
          customStyle.rel = "stylesheet";
          customStyle.type = "text/css";

          const head2: any = document.getElementsByTagName("head")(0) || document.documentElement;
          
          head.insertAdjacentElement("beforeEnd", customStyle);
          head2.insertAdjacentHTML("beforeEnd", '<META HTTP-EQUIV="refresh" CONTENT="300">');

          

      }
      else
      {
        const links = document.getElementsByTagName("link");
        for(let i=0; i < links.length;i++ )
        {


          if(links(i).href.indexOf(cssUrl)>-1){
          links(i).remove();
          }

        }


      }
    });
      return Promise.resolve();
    }
}

now the code is working well, except when I create a new page the custom CSS will be applied to the new blank page although it is not the home page. After some reading I realized that my above code will not work on new page creation, where I found this link @ https://www.eliostruyf.com/handling-page-creation-events-spfx-application-customizer to how to handle page creation navigation… but I am not sure how I need to modify my above code to handle the page creation and not load the custom CSS since the new page url != the url of the home page?

Thanks

sharepoint online – SPFX Application customizer extension fail on partial updates of our pages

I want to inject some CSS to my SharePoint page, so I follow those steps @ https://tahoeninjas.blog/2018/05/08/inject-custom-css-on-sharepoint-modern-pages-using-spfx-extensions/ to create SPFX Application customizer extension, where i did the following:-

md app-extension
cd app-extension
yo @microsoft/sharepoint

What is your solution name?: app-extension
Which baseline packages do you want to target for your component(s)? SharePoint Online only (latest)
Which type of client-side component to create?: Extension
What is your Application Customizer name? HelloWorld
What is your Application Customizer description? HelloWorld description

then i added the following code inside the .ts:-

import { override } from '@microsoft/decorators';
import { Log } from '@microsoft/sp-core-library';
import {
  BaseApplicationCustomizer
} from '@microsoft/sp-application-base';
import { Dialog } from '@microsoft/sp-dialog';

import * as strings from 'HelloWorldApplicationCustomizerStrings';

const LOG_SOURCE: string = 'HelloWorldApplicationCustomizer';

/**
 * If your command set uses the ClientSideComponentProperties JSON input,
 * it will be deserialized into the BaseExtension.properties object.
 * You can define an interface to describe it.
 */
export interface IHelloWorldApplicationCustomizerProperties {
  // This is an example; replace with your own property
  cssurl: string;
  scripturl: string;
}

/** A Custom Action which can be run during execution of a Client Side Application */
export default class HelloWorldApplicationCustomizer
  extends BaseApplicationCustomizer<IHelloWorldApplicationCustomizerProperties> {

    @override

    public onInit(): Promise<void> {
      Log.info(LOG_SOURCE, `Initialized ${strings.Title}`);
  
      const cssUrl: string = this.properties.cssurl;
      const scriptUrl: string = this.properties.scripturl;

      const url = window.location.href;
      if (cssUrl && url.toLowerCase()=="https://t****.sharepoint.com/sites/customeroperations/sitepages/dashboard.aspx") {
          // inject the style sheet
          const head: any = document.getElementsByTagName("head")(0) || document.documentElement;
          let customStyle: HTMLLinkElement = document.createElement("link");
          customStyle.href = cssUrl;
          customStyle.rel = "stylesheet";
          customStyle.type = "text/css";

          const head2: any = document.getElementsByTagName("head")(0) || document.documentElement;
          
          head.insertAdjacentElement("beforeEnd", customStyle);
          head2.insertAdjacentHTML("beforeEnd", '<META HTTP-EQUIV="refresh" CONTENT="300">');

          

      }
      
      return Promise.resolve();
    }
}

and the following inside the elements.xml:-

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomAction
        Title="HelloWorld"
        Location="ClientSideExtension.ApplicationCustomizer"
        ClientSideComponentId="e1b2d761-b43b-4006-8838-a4ba934e053f"
        ClientSideComponentProperties="{&quot;cssurl&quot;:&quot;/Style%20Library/custom.css&quot;}">
    </CustomAction>
</Elements>

So as shown in the above code I am specifying to only attach the cusotm css if the window.location.href = the url of the home page which is https://t****.sharepoint.com/sites/customeroperations/sitepages/dashboard.aspx in our case. now the above is working on most cases but is failing on the following cases:-

  1. let say i am inside the Pages library >> then I click on the “Home” link to open the home page, as follow:-

enter image description here

this will do a partial update to the page and will load the home page content without causing the whole page to load >> where in this cases the SPFX extension will not run.

  1. second case>> if I am inside the home page and the SPFX has loaded the custom css file correctly >>then i click on a page inside the news web part >> this will open the news page without refreshing the page >> which will cause the SPFX to run on the news page (which is not the home page)…

so my question is how I can force the SPFX extension to run on partial updates to check the page url, to avoid the above 2 issues?

Thanks in advance for any help.

Regards