Register JS for block on frontend only

If you’re using WordPress 5.8 (e.g. v5.8.3), then I’m afraid the answer to this: I know that I can use is_admin() to check if it’s in the editor and not load a js file but I’m trying to see how it can be done with register_block_type(). .. is it can’t; not in WordPress 5.8. More … Read more

Why is variable not working on custom sql query using wpdb?

Huge thanks to @kero !! I was finally able to create a solution by making the sql statement a variable first (as kero suggested) then using that variable on wpdb->query(); Here’s my updated and fully working codes now: $imdbid = $_GET[‘id’]; $string = file_get_contents(“http://www.omdbapi.com/?i=”.$imdbid.”&apikey=9a187152″); $json = json_decode($string, true); if( $json[‘Response’] === “True” ){ $dataID = … Read more

Automatically add custom CSS to new posts using a category template

If you have created a custom php template then add a specific class selector to your css within this template. As an example: <body class=”mycustomclass”>all your page content</body> or <content class=”mycustomclass”>all your content content</content> It doesn’t have to be on body or content or any other specific part of the page but make it encompass … Read more

An extra ‘ is displayed in the title

Those look like smart apostrophes to me. They have a curve on theme. Try: <title><?php wp_title(‘ | ‘, ‘echo’, ‘right’); ?> – <?php bloginfo(‘name’); ?></title> Otherwise post what you have around that php section too.

Adding hreflang tags automatically in WordPress subdirectory multisite

Alternatively we can set the hreflang as a site meta for each site: update_site_meta( 1, ‘hreflang’, ‘x-default’ ); update_site_meta( 3, ‘hreflang’, ‘en-au’ ); update_site_meta( 5, ‘hreflang’, ‘en-gb’ ); and then for the hreflang attribute use; get_site_meta( $site->blog_id, ‘hreflang’ ) and for the href attribute: get_home_url( $site->blog_id, $page_path ) If we want to skip the site … Read more

How can I get the page or post language when I use wpml? [closed]

From The WPML website: http://wpml.org/documentation/support/wpml-coding-api/ Language constants WPML defines the following constants which can be used in the theme: Constant Description Example ICL_LANGUAGE_CODE Code for the current language fr ICL_LANGUAGE_NAME Name of current language, in the current language Français ICL_LANGUAGE_NAME_EN Name of the current language name in English French

Missing sidebar parameter “fix” – before_content

This code detects whether a title has been set, and if not, it changes the before_widget argument. add_filter( ‘widget_display_callback’, ‘wpse4213_widget_display_callback’, 10, 3 ); function wpse4213_widget_display_callback( $instance, $widget, $args ) { if ( empty( $instance[‘title’] ) ) { $args[‘before_widget’] = ‘<div class=”container”><div class=”content”>’; $widget->widget( $args, $instance ); return false; } return $instance; } This code works … Read more

How do I let users upload files to a chosen location?

In PHP, instead of: <form method=”POST” action=”url”> Use this instead: <form enctype=”multipart/form-data” method=”post” action=”url”> You can then fetch the resulting files using the $_FILES superglobal. In WP 3.1, the whole uploads infrastructure should be available as an API unless I’m mistaking. But it won’t necessarily work on the front end, let alone allow you to … Read more