Title: AtomParser::end_element
Published: April 25, 2014
Last modified: August 20, 2026

---

# AtomParser::end_element( $parser,  $name )

## In this article

 * [Source](https://developer.wordpress.org/reference/classes/AtomParser/end_element/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/AtomParser/end_element/?output_format=md#related)

[ Back to top](https://developer.wordpress.org/reference/classes/AtomParser/end_element/?output_format=md#wp--skip-link--target)

## 󠀁[Source](https://developer.wordpress.org/reference/classes/AtomParser/end_element/?output_format=md#source)󠁿

    ```php
    function end_element($parser, $name) {

        $name_parts = explode(":", $name);
        $tag        = array_pop($name_parts);

        $ccount = count($this->in_content);

        # if we are *in* content, then let's proceed to serialize it
        if(!empty($this->in_content)) {
            # if we are ending the original content element
            # then let's finalize the content
            if($this->in_content[0][0] == $tag &&
                $this->in_content[0][1] == $this->depth) {
                $origtype = $this->in_content[0][2];
                array_shift($this->in_content);
                $newcontent = array();
                foreach($this->in_content as $c) {
                    if(count($c) == 3) {
                        array_push($newcontent, $c[2]);
                    } else {
                        if($this->is_xhtml || $this->is_text) {
                            array_push($newcontent, $this->xml_escape($c));
                        } else {
                            array_push($newcontent, $c);
                        }
                    }
                }
                if(in_array($tag, $this->ATOM_CONTENT_ELEMENTS)) {
                    $this->current->$tag = array($origtype, join('',$newcontent));
                } else {
                    $this->current->$tag = join('',$newcontent);
                }
                $this->in_content = array();
            } else if($this->in_content[$ccount-1][0] == $tag &&
                $this->in_content[$ccount-1][1] == $this->depth) {
                $this->in_content[$ccount-1][2] = substr($this->in_content[$ccount-1][2],0,-1) . "/>";
            } else {
                # else, just finalize the current element's content
                $endtag = $this->ns_to_prefix($name);
                array_push($this->in_content, array($tag, $this->depth, "</$endtag[1]>"));
            }
        }

        array_shift($this->ns_contexts);

        $this->depth--;

        if($name == ($this->NS . ':entry')) {
            array_push($this->feed->entries, $this->current);
            $this->current = null;
        }

        $this->_p("end_element('$name')");
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/atomlib.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/atomlib.php#L278)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/atomlib.php#L278-L331)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/AtomParser/end_element/?output_format=md#related)󠁿

| Uses | Description | 
| [AtomParser::xml_escape()](https://developer.wordpress.org/reference/classes/atomparser/xml_escape/)`wp-includes/atomlib.php` |  | 
| [AtomParser::ns_to_prefix()](https://developer.wordpress.org/reference/classes/atomparser/ns_to_prefix/)`wp-includes/atomlib.php` |  | 
| [AtomParser::_p()](https://developer.wordpress.org/reference/classes/atomparser/_p/)`wp-includes/atomlib.php` |  |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fatomparser%2Fend_element%2F)
before being able to contribute a note or feedback.