231
votes
Accepted
How to get URL of current page displayed?
get_permalink() is only really useful for single pages and posts, and only works inside the loop.
The simplest way I've seen is this:
global $wp;
echo home_url( $wp->request )
$wp->request ...
33
votes
Disable email notification after change of password
To disable Admin email notification when a user resets their own password, create a Plugin (or Must Use Plugin) using the following code snippet:
/**
* Disable Admin Notification of User Password ...
32
votes
Error Warning: Declaration of description_walker::start_el after PHP upgrade
The error message shows that the class description_walker extends the Walker_Nav_Menu class and overrides the start_el() method, but the signature differs from the method definition in the parent ...
31
votes
How to get URL of current page displayed?
You may use the below code to get the whole current URL in WordPress:
global $wp;
$current_url = home_url(add_query_arg(array(), $wp->request));
This will show the full path, including query ...
30
votes
Accepted
Override get_template_directory() in child theme?
Late answer, but in Wordpress 4.7 two new functions were introduced to address this question.
get_theme_file_path() (for absolute file paths) and get_theme_file_uri() (for URLs) work just like ...
29
votes
Accepted
add_action in namespace not working
Before going too far down this path I would suggest that you familiarize yourself with PHP name resolution rules.
To answer your actual question -
When you namespace functions, the fully qualified ...
26
votes
How to get WordPress Time Zone setting?
The unfortunate situation is that there are indeed two different options:
Newer timezone_string, which saves PHP–style time zone.
Older gmt_offset, which saves numeric float offset in hours.
But in ...
26
votes
Accepted
Setting $_SERVER['HTTPS']='on' prevents access to wp-admin
Special thanks to user42826.
According to the codex:
If WordPress is hosted behind a reverse proxy that provides SSL, but is hosted itself without SSL, these options will initially send any requests ...
25
votes
How to stop jQuery.migrate manually
jQuery Migrate is nothing but a dependency of the jQuery script in WordPress, so one can simply remove that dependency.
The code for that is pretty straightforward:
function dequeue_jquery_migrate( $...
21
votes
How to get URL of current page displayed?
Why not just use?
get_permalink( get_the_ID() );
That is for single pages.
For category pages, use this:
get_category_link( get_query_var( 'cat' ) );
Simple script to get the current URL of any page:...
21
votes
Accepted
error_log() output for print_r() appearing on page
The print_r function accept second parameter for return so it retrun the variable instead of printing it.
print_r($expression, $return)
So you can do
error_log( print_r( $variable, true ) );
21
votes
Transaction when using WP functions rather than vanilla SQL?
There is no functions in wordpress to handle transactions but you can easily use the $wpdb object to make a simple query to achieve this. The following function will start a transaction and then ...
19
votes
How to get URL of current page displayed?
In my case, this code worked fine:
$current_url = home_url($_SERVER['REQUEST_URI'])
I hope it will help someone, I tried all answers but this one was helpful.
19
votes
Running WP-Cron on Multisite networks the right way?
After you've added the constant in wp-config.php
defined('DISABLE_WP_CRON') or define('DISABLE_WP_CRON', true);
WP-CLI
And assuming you have your config.yml setup correctly, you can ommit the --...
17
votes
WP-CLI - Selecting PHP version
On a system where
you can't change the /usr/bin/php symlink
you can't change the PATH to point to a different version (because the php executables don't reside in distinct /lib/ directories)
...
17
votes
Accepted
What is This esc_html_e() i wordpress php?
It's a combination of _e(), which echoes a translatable string, and esc_html() which is for outputting text so that the text is not interpreted as HTML.
You would use it to prevent HTML being ...
16
votes
WordPress 6.0 class-wp-widget.php fatal errors in PHP 8.1.6
In case you couldn’t revert to PHP older than 8.1 or fix the widget registration (and you trust your 10+ years old theme), you can update the line 61 of wp-includes/class-wp-widget-factory.php this ...
16
votes
Accepted
What does the token %1$s in WordPress represent
Read the PHP docs on sprintf().
%s is just a placeholder for a string
%d is just a placeholder for a number
So an example of sprintf would look like this:
$variable = sprintf(
'The %s ran down ...
16
votes
Accepted
PHP Catchable fatal error: Object of class WP_Error could not be converted to string
Line 58 as the error indicates is this line:
$parent_term = get_term_by('ID',$term_id, $taxonomy);
$term_parents = $delimiter."<a href=\"".get_term_link($parent_term->slug,$taxonomy)."\" title=\...
15
votes
Accepted
`is_admin` returning false in backend in server side rendered block
If you have a server side rendered block in the backend, it is rendered via the REST API endpoint /wp/v2/block-renderer/xyz/blockname. This endpoint calls your render function. In the frontend the ...
15
votes
Accepted
Uncaught Error: Call to undefined function wp_generate_attachment_metadata() @ wp-cron
Some of what is usually admin side functionality is not included as part of the "main" wordpress bootstrap, files containing uploaded file manipulation functions are one of them and you need to ...
14
votes
Accepted
Include WP_Query in my own PHP file?
Load WordPress in custom PHP Script:
You need to load essential WordPress core functionality in your custom PHP script for WP_Query to work properly.
For example, let's say you have a custom PHP ...
14
votes
How to Add Custom Fields to Custom Taxonomies in Wordpress CLEANLY
You can save attachment id in options table and get to display that attachment
There are three main functions to add the meta box for taxonomy.Which are invoked through following hooks:
{...
13
votes
Running WP-Cron on Multisite networks the right way?
Easier one-liner with less bash:
wp site list --field=url | xargs -i -n1 wp cron event run --due-now --url="{}"
You can either run it manually or put it in a script and call it from cron as in the ...
13
votes
How to Add Image to Wordpress RSS-Feed with no Plug-in?
Based on the notes here and many other resources I read, I came up with this solution specifically to work with Mailchimp RSS to Email converter with the feed from Wordpress. Their templates use the &...
13
votes
Accepted
Using register_activation_hook in classes
Having reread your question, I think I see the issue, and it stems from a misunderstanding of how register_activation_hook works, combined with some confusion over how you're bootstrapping your code ...
13
votes
WP-CLI - Selecting PHP version
Got the same problem! Just switch the php version.
On my server PHP5.6 was default for apache, while CLI was configured with PHP7.1. After installing WP-CLI, with wp --info I got this result:
PHP ...
12
votes
Accepted
Run WP-CLI using PHP
Regarding the wp --info output, that makes sense. If you don't have any packages installed (see wp package --help or a global configuration files (wp-cli.yml) then those items would be blank.
You ...
12
votes
Sending the reset password link programatically
None of the above answer worked for me so I looked into wp-login.php for their default reset functionality. They used get_password_reset_key( $userData ) function . In case someone stuck up on above ...
12
votes
Disable Attachment Pages Completely
You can filter default rewrite rules and remove those for attachments:
function cleanup_default_rewrite_rules( $rules ) {
foreach ( $rules as $regex => $query ) {
if ( strpos( $regex, '...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
php × 10565functions × 1670
plugins × 1205
plugin-development × 777
woocommerce-offtopic × 558
javascript × 518
custom-post-types × 516
ajax × 495
theme-development × 441
posts × 410
loop × 409
wp-query × 398
customization × 398
jquery × 390
html × 383
shortcode × 372
mysql × 366
css × 324
categories × 303
custom-field × 290
database × 268
filters × 228
themes × 223
menus × 217
images × 212