All Questions
525 questions
346
votes
108
answers
169k
views
Best collection of code for your 'functions.php' file [closed]
As with many others who are now viewing this post, I have been reading various blogs, forums, and discussion groups to learn and improve my WordPress skills. Over the past 12 months I have been on a ...
96
votes
3
answers
44k
views
Between functions.php (theme), widgets, and plugins, which is loaded first?
Customer asks if a specific carousel plugin he uses can be widgetized. That means I should create a widget inside functions.php which calls the plugin's function. That means that the plugin's code has ...
36
votes
4
answers
10k
views
Where do I put the code snippets I found here or somewhere else on the web?
Many posts here or somewhere else contain code, but they do not say where to put it.
Example:
I have found this post: How do I turn off 301 redirecting posts (not canonical)?
I'm a newbie with PHP. ...
27
votes
4
answers
42k
views
Disable plugin / plugin action via theme
I have installed the Google Analyticator plugin on my site. I am also using the MobilePress plugin to serve up a theme designed for non-smart-phone mobile browsers. I have set up Google Analytics for ...
27
votes
4
answers
36k
views
Manually set global $post vars with an ID, in order to use template tags
I have a function retrieving ID's of posts by very specific means.
I need to be able to set the global $post in order to use functions like the_content(), which does not allow an ID as a parameter.
...
15
votes
2
answers
52k
views
Adding a second email address to a completed order in WooCommerce [closed]
Before I ask this question, I know there is a (legitimate) hesitation to answer questions here about Woo products since they have their own support and their users should be encouraged to use that. I ...
11
votes
3
answers
33k
views
How do I replace a function, declared inside a plugin's class, in functions.php?
I want to modify a function in a plugin. It is declared in the plugin's main file like this:
class WCPGSK_Main {
...
public function wcpgsk_email_after_order_table($order) {
...
}
}
Add ...
11
votes
4
answers
32k
views
How do I call wp_get_current_user() in a plugin when plugins are loaded before pluggable.php?
The current result is "PHP Fatal error: Call to undefined function wp_get_current_user()" which makes sense, but doesn't help.
I need to use $current_user.
Here is the code I'm currently using:
$...
11
votes
1
answer
6k
views
How to not allow users to create new tags, but allow to them to use existing ones
I want a certain role to be able to add new tags, but other users should just be able to use the text bar to search for existing tags.
I know I can hide the tag bar in the sidebar, but I don't want ...
10
votes
1
answer
20k
views
How to export comments in WordPress?
I want to export my comments to Excel, PDF or Word. The format really doesn't matter, I just want them exported.
I tried the Export Comments plugin, the standard one, but couldn't get it to work, I ...
9
votes
3
answers
23k
views
How to include a plugin's php file to another plugin functions file [duplicate]
I need to customize the output of the shortcode of plugin A by using a function of plugin B. So I alter the shortcode function of plugin A by inserting a condition to check the value of the function ...
8
votes
7
answers
12k
views
Gutenberg disallow certain custom blocks but keep all core blocks?
I'm writing a function to allow only some custom blocks - essentially I want to register all the blocks, then based on a database table of 'selected' blocks disallow any other custom block.
I can ...
8
votes
2
answers
30k
views
How can I call a function from one plugin within another plugin?
I have a basic plugin in the admin options panel for events.
I want to call a function that is from a different social media plugin (Mingle). I can call the plugin functions in the theme, but not ...
8
votes
1
answer
274
views
Shared functionality in plugins and themes
I recently started to develop plugins and themes and I found that I need to use several functions of on both.
Sometime I think about to check if function / class exist before declared as said on this ...
7
votes
2
answers
4k
views
Remote upload file to server B
I'm aware this might be some of the hardest coding to do ever, but thought of giving it a try.
Im basically trying to detect all (mp3) filetypes uploaded through the Wordpress media upload and send ...
6
votes
2
answers
8k
views
Publish author posts only with editor approval?
I run a multi author blog and i am looking for a non plugin solution.
The default author user role in Wordpress can publish posts without any approvel - look at Role Capabilities Wordpress Codex. ...
6
votes
2
answers
12k
views
Replacing Icons in the Dashboard
Is there a way for me to replace the icons in the WordPress Dashboard with custom ones? I'm imagining there's got to be a way to do this with the functions.php or, more ideally, with a custom-built ...
6
votes
1
answer
916
views
Keep one user logged for a year?
This has got to be simple: how do I keep one user - my-user - logged in for a year? (I'm checking logged in cookies in the dev tools console).
Update 8/16/15
This works:
add_filter( '...
6
votes
2
answers
20k
views
Remove Google Fonts Which Are (Probably) Added By Plugins
I've a theme which loads 'Open Sans' from Google Fonts. Our site is using SSL & we're using a $protocol:// to render the font URL
However, I noticed that, some plugin/(s) probably adding 3 ...
5
votes
2
answers
5k
views
How to remove WPML Generator Meta Tag by theme's functions.php (override plugin function)? [closed]
I've tried hard to find a way to not let plugin WPML output the following <meta name="generator" content="WPML ver:2.8.1 stt:3,1;0" /> tag in <head> via help of theme's function.php:
It's ...
5
votes
3
answers
3k
views
Plugin update error message
I'm working on a client website where the framework requires a specific plugin version to work properly.
With the follow lines of code in my functions.php file, it stops the plugin from updating ...
5
votes
2
answers
11k
views
Using functions from a plugin in your theme
I am a beginner to wordpress (and to php for that matter).
I am trying to understand some of the basics, and building a little e-commerce store using a plugin called "Jigoshop."
I'm reading through ...
5
votes
2
answers
3k
views
Prevent publishing the post before setting a featured image?
As the title says , I want a plugin/function to prevent/inform the user when he tries to publish the post without setting the featured image.
ANY HELP ???
5
votes
3
answers
25k
views
Limit access to posts/pages by user roles
I'm looking for a way to protect content by user roles.
Example:
you have to be registered to view posts (frontend).
If a user is a subscriber he can read post 1, 2 and 3, but if the user is a ...
5
votes
1
answer
431
views
Customizing subject in comment notification e-mails
How do you customize the following code in functions.php in order to have "New comment" as subject in comment notification e-mails instead of the default WordPress subject?
function ...
4
votes
5
answers
29k
views
if plugin is active? check if plugin is enabled or not?
I'm using the mingle plugin and the mingle-forum plugin.
I want to show a certain part on my site only if those two plugins are active. How can I solve this?
<?php if ( is_plugin_active('mingle-...
4
votes
2
answers
2k
views
Declare a function before plugin does on the theme functions.php file
I'm working with a plugin that declares a function using this format:
if (!function_exists('ABdevDND_get_current_post_type')){
function ABdevDND_get_current_post_type() {
...
}
}
I'm ...
4
votes
1
answer
1k
views
Common functionality between my own plugins
I read that when creating new post types, creating a settings page, and creating a new taxonomy, you should create a plugin. So I have done that. But I have functionality, which could be generalized, ...
4
votes
2
answers
8k
views
Why does including a file in theme's functions.php not work?
For example, if I write some code (e.d. add a custom post type or something) in my theme's functions.php, it works fine. If I move it to a new file, then include() the file in my theme's functions.php ...
4
votes
1
answer
2k
views
WP showing "warning: call_user_func_array()", What to do?
I am currently working on designing my blog and am almost done but when I updated to 5.1 WordPress version in XAMPP, it started showing up this error message:
Warning: call_user_func_array() expects ...
4
votes
1
answer
5k
views
echo value from 'select' field type into page template using cmb2?
I'm using CMB2 plugin to add metaboxes into a custom post type. I'm adding the additional metaboxes via functions.php onto child theme. It may worth to mention that parent theme/custom post already ...
4
votes
2
answers
2k
views
Editor access to plugin settings
I'm trying to give access to an user with the role Editor to this plugin settings page: https://wordpress.org/plugins/commenter-data/
In the code of this plugin on line 31 of commenter.php there is ...
4
votes
2
answers
3k
views
Need to create a Theme demo site that features multiple themes
I would like to create a site like: http://demo2.woothemes.com/?name=sentient for my clients, so that they can see the range of themes I offer. I own many templates from different providers, and ...
4
votes
1
answer
510
views
Adding a text domain to every __(), _e() and __n() gettext call without a plan to create own translations
Is it good to add a text domain as an argument to every __(), _e() and __n() gettext call such like these, even though I'm not planing to create my own translations?
__( 'Post', 'my-theme' );
_e( '...
4
votes
1
answer
24k
views
Define Function in functions.php or plugin and call in theme loop
I need to define a function in functions.php or a plugin and be able to call it inside the theme's loop & outside.
Example; I have a $product_price = get_post_meta(get_the_ID(), 'product-price', ...
4
votes
1
answer
579
views
Autogenerate wordpress shortcodes using array?
I was create a shortcode which automatically generate shortcodes with given array key and value. Function names does not generate dynamically.
Note: Array KEY = ShortcodeName and Value = Wordpress ...
4
votes
1
answer
1k
views
How to Loop Plugin Option Field Set?
Problem/Background
Currently, I'm creating a plugin for a client that will enable them to mark and modify predetermined Google Map polygons (displayed on the site) in the dashboard.
I want to let ...
3
votes
1
answer
2k
views
Can we completely remove the WordPress Sitemaps (WordPress 5.5)?
I have been using my WordPress site to create various types of content, I obviously submit my sitemaps to Google for getting my site indexed. But there is some content which I don't want on Google, ...
3
votes
2
answers
5k
views
How to handel multiple checkbox field in the admin settings page with Settings API
I'm trying to incorporate a list of checkbox in my plugin's admin settings page from which users can select a few countries from the list of all countries.
So far I've done this:
add_action( '...
3
votes
1
answer
565
views
What's the point of using Wordpress's built in admin-ajax.php?
I'm trying to understand why using admin-ajax.php is advantageous over doing something like this:
add_action ('wp_loaded', 'my_ajax');
function my_ajax() {
// Do Ajax, Check $_POST
die();
}
...
3
votes
1
answer
5k
views
wp_insert_user - how to send verification email before logging in
Using below code, I am able to create an user. But when I am login, the user is directly logging in to dashboard and there is no email sent to verify the email address. Is there any way to send ...
3
votes
1
answer
5k
views
How to override a theme function (within a class) using a plugin
I am working a website which utilises a highly complex theme (essentially a whole bunch of other software tacked onto Wordpress), so complex in fact, that child themes wont work with it.
I want to ...
3
votes
3
answers
26k
views
WooCommerce create new product and add to cart on form submit
I am customizing woo-commerce plugin to add product from the front end into the cart. I have written the function in functions.php, but i am getting a Fatal error.
Getting this error-->
Fatal ...
3
votes
2
answers
1k
views
Seeking clarification on page request life-cycle
I'm just trying to get my head around the "life-cycle" of a typical page request in WordPress. The Action Reference page lists 38 actions that occur during a typical page load, but two things aren't ...
3
votes
1
answer
2k
views
GravityForm: Populate Dropdown with custom post type [closed]
I am trying to populate a dropdown field with an array of my custom post type "color".
with this: https://www.gravityhelp.com/documentation/article/dynamically-populating-drop-down-fields/
...
3
votes
1
answer
8k
views
Generate Advanced Custom Fields box in custom admin menu page
I have created an custom admin menu page called FCC Youtube with add_menu_page function
which has some custom fields I manually generated via HTML and PHP:
code ( just the part how I created this ...
3
votes
2
answers
5k
views
Display All Non-Used Plugins
My company currently has a multisite of about 20 sites, and growing every day. We're trying to go through the plugins and set standards. IE, forms use plugin X. However, we have not found a single way ...
3
votes
1
answer
2k
views
Extend Elementor Archive Posts widget with a custom skin in order to show multiple badges
I modified my posts widget in Elementor with a custom skin in order to show multiple badges with following code:
/* MULTIPLE BADGES ON POST */
/* --- */
add_action( 'elementor/widget/posts/skins_init',...
3
votes
2
answers
1k
views
How to assign user a role if none is present when logging in
I currently have a front end part of a WP site that allows admins to create new users and assign then user roles from a drop down - that works perfectly.
However, I am using a plugin to also ...
3
votes
3
answers
106
views
Is the Wordpress HTTPS Plugin Still Safe To Use? [closed]
I have a client who wants to accept Authorize.net donations on their website. We only have a need for one page to be secured for our purposes.
I've put a lot of research into this and it seems that ...