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, '...
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 ...
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 ...
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 = ...
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 ...
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' ...
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-{...
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 ...
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 ...
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, ...
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.
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',
...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
php × 9992functions × 1591
plugins × 1131
plugin-development × 690
woocommerce-offtopic × 543
javascript × 485
custom-post-types × 483
ajax × 469
theme-development × 418
loop × 402
posts × 396
customization × 394
wp-query × 382
jquery × 377
html × 365
shortcode × 357
mysql × 353
categories × 307
css × 307
custom-field × 269
database × 246
menus × 215
filters × 211
themes × 210
images × 202