How to generate the COOKIEHASH from JavaScript

By default it’s the MD5 hash of the site URL: $siteurl = get_site_option( ‘siteurl’ ); if ( $siteurl ) { define( ‘COOKIEHASH’, md5( $siteurl ) ); } This includes the scheme but not a trailing slash, so in your example you’d need the hash of https://zeth.dk. You can also override this by defining COOKIEHASH in … Read more

useSelect second parameter

Short Answer The second parameter for useSelect is the second parameter for useCallback, so check the React website and you’d understand what the heck that second parameter is.. 🙂 Long Answer useSelect is a custom React hook which uses the core useCallback hook in React which returns a memoized callback which can avoid expensive calculations … Read more

How to display post content in the block editor

It is true that using RawHTML (or dangerouslySetInnerHTML) is discouraged and indeed prone to XSS attacks like <img src=x onerror=alert(1)//> and <p>abc<iframe//src=jAva&Tab;script:alert(3)>def</p>. But if you need to set HTML directly from React, then you’ll have to use dangerouslySetInnerHTML, either directly (e.g. <div dangerouslySetInnerHTML={ ({ __html: ‘foo <b>bar</b>’ }) } />) or via RawHTML in Gutenberg … Read more

Looping over wordpress meta to create “ ‘s?

Does select(“core/editor”).getEditedPostAttribute(“meta”) get the whole post meta? Only the meta registered using register_post_meta() or register_meta() with the show_in_rest argument set to true. So for example, the meta can be registered like so: register_post_meta( ‘post’, ‘_postcode_pricing_postal_town’, array( ‘show_in_rest’ => true, ‘single’ => true, ‘type’ => ‘string’, // I set this because the meta is *protected*, i.e. … Read more

is_page_template() written in jquery/javascript

Well, yes, in WordPress, different templates have a different body class name. If you inspect the body classes on a specific page in WordPress, there should be a body class page. You can detect the template by checking if the class exists like so: jQuery(document).ready(function($){ if ( $(‘body’).hasClass(‘page’)) { // add your logic here } … Read more

Display a div when post has a certain tag

You could use a simple conditional and check if the post has a term using has_term(): has_term( $term, $taxonomy, $post ); Pass in your Term Slug, the taxonomy ( which sounds like you’re using post_tag and the post object, no javascript needed. <?php if( has_term( ‘term_slug’, ‘post_tag’, $post ) : ?> <div> Show your div … Read more

Scripts not loading through function Method in WordPress Theme

There are several fundamental problems with what you’re trying to do that prevent you reaching your goal The Problems Naming You register 2 scripts, but you name them both ‘custom’. How is WordPress supposed to know which script you meant when you later tell it to display ‘custom’? /* Register scripts. */ wp_register_script( ‘custom’, JS … Read more

disable tags on wordpress text editor

WordPress already disallows the use of JavaScript in the editor for users without the unfiltered_html capability. By default, only the Administrator and Editor roles have this capability. If necessary, you could remove this capability from Editor users as well. (It doesn’t make sense to remove it from Administrators, because they will still have the ability … Read more