Function not working inside of a function in functions.php

Remove the function inside the function, and instead call the wp_register_script and register_block_type inside the large function. Finally, remove the inner add_action() call, so you only have the ending one for the large function. function irm_lockdown_author_role() { if (isset($userrole->roles[0])) { $current_role = $userrole->roles[0]; } else { $current_role=”no_role”; } if (‘author’ == $current_role) { /* function … Read more

Adding a tag_ID column into Categories inside the admin dashboard?

You can do it like so: Use the manage_<screen ID>_columns filter to add the “ID” column. Example for the default category taxonomy where <screen ID> is edit-category — for other taxonomies, it would be edit-<taxonomy> like edit-post_tag: add_filter( ‘manage_edit-category_columns’, ‘my_manage_edit_category_columns’ ); function my_manage_edit_category_columns( $columns ) { // Add the “ID” column. $columns[‘term_id’] = ‘ID’; // … Read more

Why does the post_type_link hook everything twice?

When you add a filter to post_type_link, you are telling WordPress to run the hooked function on the result of the get_post_permalink() function. So any time that function runs, so does yours. When I tested the filter myself, I only saw a printed message once for each link, but if you have something like this: … Read more

Extending a custom framework built into WordPress to automatically turn the ‘Search Engine Visibility’ setting ON / OFF, dependant on environment

Those “definable settings” are constants. WordPress defines its default constants in this file. If a constant definition is wrapped in a defined() check, like this: if ( ! defined( ‘WP_DEBUG_DISPLAY’ ) ) { define( ‘WP_DEBUG_DISPLAY’, true ); } Then it means you can define it first in the wp-config.php file (or, apparently, this framework’s config … Read more

Custom meta box values are not getting saved for my custom post type

but remaining values (checkbox, select, images) are not getting saved I believe those fields are also getting saved, but you are just not displaying them correctly. And you should always escape input/textarea values, e.g. use esc_attr() for single-line inputs and esc_textarea() for textareas (multi-line inputs). So to make your code work correctly, try these: First … Read more

require_once() if a product in woocommerce contains a tag [closed]

has_term() is a template function therefore it does not work if you use it straight in functions.php which is loaded well before knowing if the current object is a product page. So if you use it in functions.php you could do: add_action(‘template_redirect’,’my_inclusion_function’); function my_inclusion_function(){ if(is_product() && has_term(‘xyz’, ‘product_tag’)){ require_once( WP_CONTENT_DIR.’/path/file.php’); } } is_product() checks if … Read more

Wp-query Order By problem

The “problem” seems to be the default value that order receives, its always DESC unless told otherwise. You will need to create your own order after getting the posts, so something like this. $my_query = new WP_Query($query_args); $ordered_posts = []; foreach(explode(‘,’, $idpaginas) as $rpid) { foreach($my_query->posts as $index => $fpid) { if($fpid->ID == $rpid) $ordered_posts[] … Read more