5 votes

Enqueue script o style only if a template part is loaded

You can use the get_template_part_{$slug} hook, which fires before a template part is loaded. You can find the reference here, which I find more useful than the official reference. So, I tested it in ...
user avatar
  • 181
4 votes
Accepted

Disable External Pingacks on WordPress Posts and Only Allow 'Self Pings'

If you want to receive only linkbacks from your own WordPress site, then try both of these: But if you want to allow all that were sent as trackbacks (where the comment type is trackback), then just ...
user avatar
  • 31.3k
4 votes
Accepted

Change the slug of a particular page every x hours

You'll need a two step process for that. Create a function that actually changes the slug (not rewrite it) Schedule an event in WordPress to run that function in every X hours. Here are something to ...
user avatar
  • 2,600
4 votes
Accepted

What is @Action in Wordpress?

This is called php annotations. Many of them are built-in via a standard called phpdoc (like @var), and they are used by the interpreter or the static tools (also by humans for a more structured ...
user avatar
  • 91
3 votes
Accepted

Sort registered users by post count? (inside admin dashboard)

Try the following code: add_filter('manage_users_sortable_columns', 'my_user_sortable_columns'); function my_user_sortable_columns($sortable_columns) { $sortable_columns['posts'] = 'post_count'; ...
user avatar
  • 271
3 votes

How to log out everywhere else, destroy all sessions "all other devices"?

I know this is an old topic but destroy_all() will destroy all sessions but destroy_others() destroys all sessions except the current session Destroy all sessions: $sessions = WP_Session_Tokens::...
user avatar
  • 31
3 votes

Button generate a random URL

It looks like your code works as written. Alternatively, you can generate an alphanumeric string using uniqid()... <a href="http://meet.jit.si/<?php echo uniqid()?>" target="...
user avatar
3 votes

Noscript not working as it should in wordpress site

That's not how <noscript> tags work, and if they did your usage is incorrect. The <noscript> tag defines an alternate content to be displayed to users that have disabled scripts in their ...
user avatar
  • 51.7k
2 votes
Accepted

Illegal string offset in PHP function

You need to be validating a couple of parts about $filearray before you use it. There are some good suggestions in the comments, I think a couple of robust examples would serve you well too: Using ...
user avatar
  • 2,929
2 votes

Changing the post date and time with function

The selected answer is perfect for modifying the "publish date", but in my case I wanted to change the "last modified" date (post_modified and post_modified_gmt in the db). The ...
user avatar
  • 121
2 votes
Accepted

How can I load a javascript file that is type="module" the Wordpress way?

Here is the final code I now use to add type="module" to my scripts. wp_register_script('my-script', get_theme_file_uri('/js/script.js'), ['axios'], '1.0'); wp_enqueue_script('my-script'); ...
user avatar
  • 463
2 votes

How to load parent theme template parts in child theme

From the WordPress documentation on child themes (Referencing or Including Other Files): To reference the parent theme directory, you would use get_template_directory() instead. Therefore, in your ...
user avatar
  • 121
2 votes
Accepted

Show meta box only for default page template

If the "Default Template" option is selected from the Template dropdown, then WordPress will set the value of the _wp_page_template meta to default and not page.php, so that's most likely ...
user avatar
  • 31.3k
2 votes
Accepted

What is the text that appears beside the page titles in the list of pages in the WP admin?

It's called post state, but not to be confused with post status (publish, draft, etc.) (although the state can of course contain the post status), and the core WordPress function which adds the post ...
user avatar
  • 31.3k
2 votes

Change slug shortlink “/?p=” base in WordPress

Go to Settings->Permalinks and set a custom structure as: /post/%post_id% or just /%post_id%
user avatar
  • 271
2 votes
Accepted

Omit custom post type from wp-sitemap.xml based on meta key using wp_sitemaps_posts_query_args

The error happens because the filter callback (shapeSpace_disable_sitemap_post_meta()) expects to receive two parameters ($args and $post_type) and yet you call add_filter() without setting the fourth ...
user avatar
  • 31.3k
2 votes

Update Content based on expiration time or queued processing

Few things come to my mind, which could help. Post status Perhaps you could use the pending post status, which you would use as a parameter in aggiorna_dati(), for the auto-generated posts that needs ...
user avatar
2 votes
Accepted

How to remove comment count column in Posts inside the admin dashboard?

Should be work, if you use the filter manage_posts_columns. The hook is fine, see https://core.trac.wordpress.org/browser/tags/5.8/src/wp-admin/includes/class-wp-posts-list-table.php#L714 ...
user avatar
  • 16.5k
2 votes
Accepted

How to obtain the recent posts without their content in an efficient way?

How to obtain the recent posts without their content? The same way you would any other post, just don't use the post content. Not fetching the post content will not improve performance, and may ...
user avatar
  • 51.7k
2 votes
Accepted

How do I modify the custom footer text and get theme version number to show in wordpress admin?

Try returning your span instead of echoing it. function modify_admin_footer() { return '<span id="footer-thankyou">Developed by <a href="http://www.toolcart.com" ...
user avatar
  • 7,382
2 votes
Accepted

Edit the_category (); for a hierarchical display

You could assign the post only to the child category, and call the function like so: the_category( ' ', 'multiple' ); This will output (notice the whitepsace between the anchor tags): <a href=&...
user avatar
2 votes
Accepted

Override a function defined in wp-includes/comment-template.php

If you look at the end of the function get_cancel_comment_reply_link( $text = '' ) in the file wp-includes/comment-template.php, you see the filter cancel_comment_reply_link. return apply_filters( '...
user avatar
  • 136
2 votes
Accepted

Determine if, within a post, you are on page 2 or greater - Wordpress documentation circular

The problem is that it also shows the featured image, in the same spot, on pages 2, 3, 4, etc of the same article (when I have used <!--nextpage-->). The featured image should only show on the ...
user avatar
  • 31.3k
2 votes

If ACF field is empty show different value

This is basically a php question. add_filter( 'facetwp_map_marker_args', function( $args, $post_id ) { $field = get_field( 'Type', $post_id ); // Get this post's ACF value $tent = 'tent'; ...
user avatar
  • 5,257
2 votes
Accepted

Enable taxonomies by post type in an array of CPTs

I have tweaked theyour code and it should work.. please give it a try add_action('init', 'all_custom_post_types'); function all_custom_post_types() { $types = array( array('the_type' => '...
user avatar
2 votes
Accepted

Set Taxonomy based on post status

This is what works with the help of WebElaine above. I had to pass the postID to has_category() and then set variables. function add_categories_automatically($postID) { $p_published = ...
user avatar
  • 95
2 votes
Accepted

WP function won't work on 404 template page

the_time does not display the current date, it displays the date of the current post, and 404 pages do not have a current post. For this reason, if it ever returned a date on the 404 page then it ...
user avatar
  • 51.7k
2 votes
Accepted

Custom editor color palette colors are not appearing in the editor

I noticed that you're using a child theme of Twenty Twenty-One, which also registers custom editor color palette using the same hook and priority (i.e. 10), so try using 11 or greater as the action's ...
user avatar
  • 31.3k
2 votes
Accepted

Scope for PHP Variables Assigned in functions.php or a plugin

Nope! There is no way. variable scope is file based in PHP, It means you can't access a variable or even function and class from another file unless you include that file inside current file or use ...
user avatar
2 votes
Accepted

How can I add a filter for specific categories on functions.php?

As pointed out in this answer, using the request filter means that some (if not all) of WordPress's is_* functions are unavailable. Use the corresponding member functions of your new WP_Query instead, ...
user avatar
  • 10.2k

Only top scored, non community-wiki answers of a minimum length are eligible