A function is a sequence of program instructions that perform a specific task. It is packaged as a unit that can be used wherever the according task should be performed.

learn more… | top users | synonyms (2)

5
votes
2answers
1k views

Modify Admin Bar Link

Starting on line 474 of /wp-includes/admin-bar.php there is a function that is declared as the following: function wp_admin_bar_new_content_menu( $wp_admin_bar ) What it does it generates the + New ...
5
votes
2answers
246 views

username_exists() function can't be access without logging in

I'm using the following function in functions.php to check if a username exists in the DB function check_username() { $username = $_POST['user']; if ( username_exists( $username ) ) { ...
5
votes
1answer
1k views

Set JPEG compression for specific custom image sizes

I use various custom image sizes (by add_image_size) and I have set my JPEG compression to 30% with this filter: function jpeg_quality_callback($arg) { return (int)30; } add_filter('jpeg_quality', ...
5
votes
4answers
2k views

Removing Metabox for “Slug” without removing functionality

Here is an interesting question. I have recently noticed that if you utilize the code remove_meta_box('slugdiv', 'post', 'normal'); you are actually unable to modify the slug when you click on ...
5
votes
1answer
881 views

how to group custom post types

hi wanted to know do i group my custom post types to appear together in a group in the wordpress back end menu bar like this below in the picture what code do i have to use in my functions.php so that ...
5
votes
2answers
3k views

Function to execute when a post is moved to trash .

Hi is there an action which can be performed while a post is moved to trash .... I tried delete_post and deleted_post. It works but twice for each action ( before and after the action as written in ...
5
votes
3answers
3k views

Passing arguments to a admin menu page callback?

Situation: I'm working on a plugin and I'm developing it as a class, everything worked fine until I run into this situation. I wanted to make things a bit cleaner and tried this.. class MyPlugin { ...
5
votes
2answers
2k views

How can I get $id variable in widget's form function?

How can I get $id variable in widget's form function? According to widget's structure I see that widget function have $args as a parameter, which will be extracted in function's body. In my case i ...
4
votes
4answers
358 views

One Child Functions.php for Multiple Child Themes

I have a wordpress setup that I use for clients with around 30 or so child themes that they can choose from. Each child theme has it's own functions.php file currently. Is it possible to setup just ...
4
votes
3answers
9k views

Link to user's profile settings page?

I'm trying to figure out how to link a logged-in user to his profile settings, but I can't seem to find a function that generates this link (like wp_settings_url() or wp_profile_url()) Is there a ...
4
votes
3answers
5k views

Perform an action when post is updated/published

I'd like to run a custom query using some meta data whenever a post is updated or published. Is there something I can put in functions.php to fire when those events occur?
4
votes
7answers
5k views

Include files in child theme functions file

Typically in my theme function file I'll require other files to keep things neat. require_once("foo.php"); Now working in a child theme I'd like to do that same. I'm adding custom admin options and ...
4
votes
3answers
1k views

clients list using wordpress

I am using wordpress for my new website and i have list of clients(name and their logos). I am confused how to make those editable using wordpress? Html as follows... <ul> <li><img ...
4
votes
4answers
287 views

Display custom comments field for first level only

I have simple fuction that adds additional comment form field called "Subject": add_action( 'comment_form_logged_in_before', 'additional_fields' ); add_action( 'comment_form_before_fields', ...
4
votes
2answers
694 views

Shared functions.php across multiple WordPress websites

I find myself using many of the same snippets of code for my functions.php file in new websites. Is there a method I can use to create a few different shared functions.php files to use across my ...
4
votes
3answers
165 views

How to restrict actions and filters “properly” by conditions

Which one is correct when adding actions/filters/etc.... Both methods work fine and I've seen people do things both ways, but I'm assuming one is correct. My gut tells me that wrapping the if ...
4
votes
5answers
4k views

Relative URLs and hide /wp-content/themes/

in my header and other sections I would like to use <script src="/incs/js/script.js"></script> While maintaining the default theme folder structure in server as below ...
4
votes
3answers
919 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 ...
4
votes
2answers
705 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 ...
4
votes
3answers
166 views

bloginfo() vs get_option?

What's the difference between: bloginfo('name'); vs get_option('blogname'); The parameter is just an example, but I see no differences in terms displaying what I want. Are there any particular ...
4
votes
2answers
541 views

Removing default image size list in Media Box

I trying to remove unused image size (Thumbnail, Medium, Large) in MediaBox Any function can i use in functions.php ? or some trick ? PS : I know i can use jQuery trick but any better function to ...
4
votes
1answer
1k views

function deactivate_plugins does not exist

I am getting function deactivate_plugins does not exist error when calling this function function deactivateSelf(){ deactivate_plugins(RSD_PLUGIN, true); //gives error: function ...
4
votes
2answers
2k views

Excluding iPad from wp_is_mobile

I am eperiencing a very annoying problem. I built my website with media queries and is_mobile (thinking is_mobile would be the same as smaller screens. How foolish of me.) but after some testing ...
4
votes
1answer
165 views

function_exists call in function.php

In the function.php file of the twentyeleven the setup function checks to see whether it exists before running it: if (!function_exists('twentyelevent_setup')): function twentyelevent_setup() { ... ...
4
votes
1answer
535 views

Can I turn off write-in tags/taxonomies?

One of the big problems my site staff has had with tags is the overwhelming number of similar or duplicate tags, due to the write-in ability. I'm about to add new custom taxonomies to my site for ...
4
votes
2answers
80 views

remove_action on after_setup_theme not working from child theme

I am trying to remove a theme action for an elegant-themes theme using a child theme.. This works when I remove action after add_action code anywhere in the parent theme functions.php. However, it ...
4
votes
2answers
4k views

Add multiple custom fields to the general settings page

What I would like to do is to add a few custom fields to the general settings. This is the code that Im using. It works allright but I just cant figure how to add more fields. I would like to create ...
4
votes
1answer
1k views

Remove a menu item created by a plugin

I'm trying to remove a menu item and tried several approaches, but have not had any luck. It was created from a FAQ plugin. If I use this line: remove_menu_page( 'edit.php?post_type=question' ); ...
4
votes
2answers
2k views

Enabling Sessions in WordPress 3.0

Im using a wfcart in my WordPress site but for some reason on certain pages WordPress drops the session I'm wondering if there is a way to enable sessions in WordPress 3?
4
votes
1answer
68 views

How to add classes to images based on their categories?

I need to be able to: 1.) assign categories to images and 2.) add classes to all images that correspond to their assigned categories. I was able to add categories to images with the following: ...
4
votes
2answers
3k views

wp_enqueue_script was called incorrectly

Hello I don't know how but now I am getting this error Notice: wp_enqueue_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, ...
4
votes
2answers
212 views

Notify users whenever a new post is published based on their preference

I have put together a custom registration form on my WordPress site and one of the items on the registration form is an ability to select an interest. Essentially I have the following code from the ...
4
votes
2answers
260 views

current_cat_ancestor Alternatives

It looks like adding current-cat-ancestor class to category list was proposed, but never implemented. The only way I've been able to find so far is to re-create the wp_list_categories() function ...
4
votes
1answer
2k 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 ...
4
votes
2answers
827 views

Build a content and excerpt grid loop with paging and options for # of posts

What I'd like to do: on index.php, a loop that shows a selectable number of full posts using the_content and then below that shows a selectable number (the number of posts can be hardcoded in the ...
4
votes
1answer
3k 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 ...
4
votes
1answer
2k views

wp_get_attachment_image returns different image size

It is a bug? wp_get_attachment_image( $attachment_id, 'post-thumb-size-small'); Same code, called in template, and in AJAX call returns same image SRC, but different image width and height. dumb ...
4
votes
2answers
859 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 ???
3
votes
4answers
7k views

How do I remove UL on wp_nav_menu?

I search on this site and found many answers for this question. Most of them is not working on my theme. Here is a one solution I found and it's working according to my need. function ...
3
votes
2answers
4k 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 ...
3
votes
2answers
3k views

How to detect single.php (but not single-portfolio.php)?

When I'm using is_single(); in my <head> section to add some style to website navigation it executes correctly on blog posts but it also executes on single "portfolio" post type posts (so ...
3
votes
3answers
22k views

How to set and use global variables? Or why not to use them at all

UPDATE: My original question has been solved, but this is turning into a valid discussion about why not to use global variables, so I am updating the question to reflect that. The solution was ...
3
votes
2answers
7k views

Get the ID of the page a menu item links to?

I am currently using a custom walker to customize the output of wp_nav_menu(), and I am trying to add additional information to the <a> tags. What I want the output for each menu link to look ...
3
votes
3answers
3k views

Forcing all posts associated with a custom post type to be private

Does anyone know of a way to add code to the functions.php file which will automatically force all posts belonging to a custom post type to be "private" and/or "password protected" with a default ...
3
votes
1answer
2k views

What is the “with_front” rewrite key?

I have the following line in a register_post_type function: 'rewrite' => array('slug' => 'Newsletters', 'with_front' => false), I understand what the line does in general (adds ...
3
votes
5answers
2k views

Removing custom background and header feature in child theme

I am creating a child theme using twentyten as my base. I am looking for a way to remove the features of adding custom header and background without touching functions.php file in the parent theme. ...
3
votes
1answer
3k views

How do I make my function add variables/values to the $post object?

How do I add $tzDesc and $tzEmbed (and other variables) to the $post object in the following function so that I can display the values in my theme files by inserting <?php echo $tzDesc; ?>? ...
3
votes
2answers
18 views

Check if the user has explicitly set an excerpt

Is there a way for me to check if the user has explicitly set an excerpt? I need to call the excerpt only if they've specified something in the excerpt field, and not an automatically shortened ...
3
votes
2answers
89 views

How to count number of functions attached to an action hook?

I have some actions like this function simple_notification() { echo '<div>This is a notification</div>'; } add_action( 'site_notices', 'simple_notification' ); ...
3
votes
3answers
965 views

Child theme functions.php do I use php open and close tags?

I setup a child theme which works fine. It's importing the main style.css and has custom css styles along with custom header.php and footer.php files When using functions.php in a child theme it's ...