• Resolved u3r

    (@u3r)


    Hi, is there a way to delete first two words XML title?

    Example. I have this:
    <title>195/60R15 88T M200 MENTOR DOT2012</title>

    I want the title to end up being: “M200 MENTOR DOT2012”. (If it’s possible, I even would like to delete the very last word too. So it’s “M200 Mentor”.)

    The title has a different amount of words every time.

    Any help is appreciated. Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @u3r,

    Hi, is there a way to delete first two words XML title? If it’s possible, I even would like to delete the very last word too. So it’s “M200 Mentor”.

    You can use a custom PHP function to do that: https://www.wpallimport.com/documentation/developers/custom-code/inline-php/. Here’s an untested example:

    function my_remove_words( $string ) {
    	$string = preg_split( '/\s+/', $string );
    	array_pop( $string );	
    	return implode( ' ', array_slice( $string, 2 ) );
    }
    Thread Starter u3r

    (@u3r)

    If my XML line looks like <title>actual title here</title>

    am I supposed to use this code as:

    <?php
    function my_remove_words( $title ) {
    	$title = preg_split( '/\s+/', $title );
    	array_pop( $title );	
    	return implode( ' ', array_slice( $title, 2 ) );
    }
    ?>

    If so, it doesn’t work.

    • This reply was modified 5 years, 9 months ago by u3r.
    • This reply was modified 5 years, 9 months ago by u3r.
    Thread Starter u3r

    (@u3r)

    Solved.

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

The topic ‘Delete first words from title?’ is closed to new replies.