Articles of functions

Hook for altering the content of all wp mails

Hi i want to set email template for all mails for my site . I know how to set up mail template and i set mail template for each of my mail by editing the code ie wp_mail( $recipient, $subject, $body, $headers, $attachments ); is mail code then i replaced it with ob_start(); require_once (get_template_directory() […]

White screen error for a custom theme

I have created a theme for one of our clients using bootstrap framework! When i was working on it on Localhost it works Correctly, but when I Uploaded it doesn’t work. When I Activate it from Appearance I Saw A blank white Page; Also when I Try to Post a new Comment, post, page or […]

Where do I store custom functions that call custom page template files?

I’ve created a WordPress Page template called head.php I then went into /wp-includes/general-template.php and by replicating the default get_header() function that is already there I added this new custom function underneath : function get_head( $name = null ) { do_action( ‘get_head’, $name ); $templates = array(); $name = (string) $name; if ( ” !== $name […]

Removing parent theme CSS without editing parent theme

I am currently developing a child theme that builds on twentyfifteen as a parent theme. However a potential issue has cropped up that is causing a problem. I want to strip the CSS and JS assets from the parent theme twentyfifteen, but these are loaded from the theme’s functions.php file with wp_enqueue_style and wp_enqueue_script, I […]

How to set default archive image without overriding first attached image?

I have hit a wall. I have archive pages with some posts that have featured images which display fine. Some posts don’t have featured images but the first attached image displays. Some posts have no images and there is a blank space. I have been trying all day to find a way to display a […]

Display random text from a file with the WP built-in AJAX API

I want to use a solution by @toscho to display and rotate some quotes. The unchanged code works very well, but if I replace the protected function get_rand() { return rand( 1, 1000 ); } with (from here) protected function get_rand() { $array = file(“wp-content/plugins/quotes-rotator/quotes.txt”); $r = rand(0,count($array)-1); return $array[rand(0,count($array)-1)]; } the code works well […]

What is the correct way to include my new functions and scripts in WordPress?

To include new functions we can write them in the theme’s functions.php. But I have to write my own functions in a new file rather altering the theme’s function.php. I can write any custom js action in footer.php, but I need to write it in other file. How can I do this? Is there any […]

Include Jquery libraries in wordpress theme?

I have a file in my theme’s JS folder named cycle2.js. How do I include the Jquery from ‘wordpress→includes’ into my theme? How do I load this custom JavaScript file ‘cycle2.js’ into my theme? I have: function watercolor_js_scripts(){ if (!is_admin()) { wp_register_script(‘cycle2’, get_template_directory_uri() . ‘/js/cycle2.js’, ‘jquery’, TRUE); wp_enqueue_script( ‘jquery’ ); wp_enqueue_script( ‘cycle2’ ); } add_action(‘init’, […]

Function to replace comment's accented characters before posting

I have some weird problems with encoding my WordPress website and I can’t add comments with accent words. when i try to do it, i received error by WP. What i need is just a function that read the comment before it has inserted and transforms all the accented characters with normal characters with no […]

Change Slug of a Custom Post Type

I use a plugin that creates a custom post type with a slug that I am wanting to change. I don’t want to overwrite the plugin files, so I’m wondering how I can change the slug using a separate function? Thanks. // Register post type add_action( ‘init’, ‘ctc_register_post_type_item’ ); function ctc_register_post_type_item() { // Arguments $args […]