Title: Function returning: Warning: Missing argument 1
Last modified: August 20, 2016

---

# Function returning: Warning: Missing argument 1

 *  [ameraz](https://wordpress.org/support/users/ameraz/)
 * (@ameraz)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/function-returning-warning-missing-argument-1/)
 * Hey there guys!
    I wrote this couple of functions, that alternate a exploded 
   Custom Field string with the post permalink:
 * (where the Custom Field should look like this: ex. Google++http://google.com”)
 *     ```
       // Custom Permalink
       function custom_permalink($url){
           global $post;
           $link = get_post_meta($post->ID,'link',true);
           if ($link) {
               $pieces = explode("++", $link);
               $url = $pieces[1];
           } else {
               $url = the_permalink();
           }
           return $url;
       }
   
       // Via Text
       function via_text($url){
           global $post;
           $link = get_post_meta($post->ID,'link',true);
           if ($link) {
               $pieces = explode("++", $link);
               $url = ' <span><a href="'.$pieces[1].'">Via '.$pieces[0].'</a></span>';
           } else {
               $url = ' ';
           }
           return $url;
       }
       ```
   
 * … which work all right when tested on a MAMP server, but when deployed they return:
 * “Warning: Missing argument 1 …”
 * Any idea why this might be happening?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [ameraz](https://wordpress.org/support/users/ameraz/)
 * (@ameraz)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/function-returning-warning-missing-argument-1/#post-2999624)
 * The strangest thing is that even when deployed the functions return the expected
   outcome after the “Warning: Missing argument 1…” leyend
 * ex.
 *     ```
       <div id="excerpt">
       Lorem ipsum dolor sit amet...
       <br>
       <b>Warning</b>
       : Missing argument 1 for via_text(), called in /home/.../index.php on line 24 and defined in
       <b>/home/.../functions.php</b>
       on line
       <b>80</b>
       <br>
       <span>
       <a href="http://google.com">Via Google</a>
       </span>
       </div>
       ```
   
 *  Thread Starter [ameraz](https://wordpress.org/support/users/ameraz/)
 * (@ameraz)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/function-returning-warning-missing-argument-1/#post-2999811)
 * Ok… I figured it out…
    this happens when a class gets instantiated and theres
   no default argument for the constructor…
 * here are the working functions…
 *     ```
       // Custom Permalink
       	function custom_permalink($url='') {
       		global $post;
       		$link = get_post_meta($post->ID,'link',true);
       		if ($link) {
       			$pieces = explode("++", $link);
       			$url = $pieces[1];
       		} else {
       			$url = the_permalink();
       		}
       		return $url;
       	}
   
       	// Via Text
       	function via_text($url='') {
       		global $post;
       		$link = get_post_meta($post->ID,'link',true);
       		if ($link) {
       			$pieces = explode("++", $link);
       			$url = ' <span><a href="'.$pieces[1].'">Via '.$pieces[0].'</a></span>';
       		} else {
       			$url = ' ';
       		}
       		return $url;
       	}
       ```
   
 * in case anyone is in need…
    what they do:
 * in case theres a post with the Custom Field ‘link’ (like so: Google++http://google.
   com) the function will replace the permalink with the Custom Link. So in the 
   theme call: echo custom_permalink(); … instead of the_permalink();
 * the via_text() function works a little different; it calls a span tag with the
   Custom Field ‘link’ exploded like so:
 * `<span><a href="http://google.com">Via Google</a></span>`
 * hope this works for somebody else
 * 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Function returning: Warning: Missing argument 1’ is closed to new replies.

## Tags

 * [function](https://wordpress.org/support/topic-tag/function/)
 * [warning](https://wordpress.org/support/topic-tag/warning/)

 * 2 replies
 * 1 participant
 * Last reply from: [ameraz](https://wordpress.org/support/users/ameraz/)
 * Last activity: [13 years, 8 months ago](https://wordpress.org/support/topic/function-returning-warning-missing-argument-1/#post-2999811)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
