Hot answers tagged

4 votes
Accepted

Make PHP work with HTML tags

From your code the proper structure would be if ( is_singular() ) { if (get_post_meta(get_the_ID(), 'square_image', true)) { echo '<img src="' . get_post_meta($post->ID, '...
user avatar
4 votes
Accepted

Find variables available at a given hook

In general the best solution would be to refer to the documentation for the hook - or the source for the action call within WordPress core's codebase if the documentation proves insufficient. You can ...
user avatar
  • 5,155
3 votes
Accepted

Escape when echoed

In fact to be super pedantic, I think the correct code is actually: echo '<option value="' . esc_attr( $folder ) . '">' . esc_html( $folder ) . '</option>'; Since the first ...
user avatar
2 votes
Accepted

Finding the screen id of a page generated with add_menu_page

The function add_menu_page return the hook suffix that inform you about the current page. A simple example to get the hook suffix. public function add_menu_page() { $page_hook_suffix = ...
user avatar
  • 16.6k
1 vote

php redirect with custom user roles set and working but redirect not working for when users are logged in

If the user is logged-in, the function returns before the redirect code lower in the function. if( is_user_logged_in() ) { return; } Since you want the redirect code to run only if the user is ...
user avatar
  • 4,860
1 vote
Accepted

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' ...
user avatar
  • 63.9k
1 vote
Accepted

Javascript code inside "<# #>" in core WordPress files .php

These are Underscore Templates, handled by the wp.template() JavaScript function (source here) which takes in a template ID corresponding to a <script type="text/html" id="tmpl-{...
user avatar
  • 5,155
1 vote
Accepted

how to get serialized post meta

get_post_meta() with the 3rd parameter set to true will return a single item with the key specified in the 2nd parameter (_custom_field in your code). If this item is an array, it'll return as the ...
user avatar
  • 10.2k
1 vote
Accepted

Hide Heading if ACF Field is empty

Move the outer(of the two) div.local_faq inside the if statement which checks if the faq field is set, because that’s the outer parent container. Also it would make sense to change the outer container ...
user avatar
  • 2,315
1 vote
Accepted

Scheduling an event inside plugin class is not working

I assumed that the post function is simply not found so when the time comes for that function to run, nothing happens The second parameter for wp_schedule_single_event() is actually an event name, ...
user avatar
  • 31.4k
1 vote
Accepted

How to remove the message 'We could not find any results for your search' without changing template files and without adding posts/pages?

The answer was to change the input name variable of the form. It was 's' for my widget.
user avatar
1 vote

How to set a template with wp_insert_post

You can check this code I am able to work with this function cutom_function() { $new_page_id = wp_insert_post( array( 'post_title' => 'PKB', 'post_type' => 'page', ...
user avatar
1 vote
Accepted

Wordpress Custom SQL Table with UserID Filter for results

The evolution of this question makes it difficult to succinctly answer, but in brief summary: Using $wpdb->prepare() to construct arbitrary SQL queries to execute against the database helps to ...
user avatar
  • 5,155
1 vote
Accepted

Automatically add images to a menu

I guess you need this function get_the_post_thumbnail_url($menu->object_id); (provided menu item is not a custom link) $menu->ID is not the id of the post/page it is linking to. About calling ...
user avatar
  • 488

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