Cambiar URL "Event"

  • Autor Autor josemanuelprz24
  • Fecha de inicio Fecha de inicio
J

josemanuelprz24

Beta
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Hola que tal.

Estoy trabajando en un proyecto Wordpress y hay una seccion donde se pueden crear eventos, pero la url por defecto es "event" EJ:

example.com/event/nombre-del-evento

y me gustaría que dijera:

example.com/eventos/nombre-del-evento

Existe la posibilidad de cambiar esto?

Anduve buscado por los archivos PHP, y el que más se le acerco fue este:

PHP:
<?php

require_once( 'post_type.class.php' );
require_once( 'event_metaboxes.php' );

STM_PostType::registerPostType( 'event', __( 'Event', STM_DOMAIN ), array( 'menu_icon' => 'dashicons-calendar', 'supports' => array( 'title', 'editor', 'thumbnail', 'comments' ), 'taxonomies' => array( 'post_tag' ) ) );
STM_PostType::addTaxonomy( 'event_category', __( 'Categories', STM_DOMAIN ), 'event' );

STM_PostType::registerPostType( 'donation', __( 'Donation', STM_DOMAIN ), array( 'menu_icon' => 'dashicons-download', 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ), 'taxonomies' => array( 'post_tag' ) ) );
STM_PostType::addTaxonomy( 'donation_category', __( 'Categories', STM_DOMAIN ), 'donation' );

STM_PostType::registerPostType( 'volunteer', __( 'Volunteer', STM_DOMAIN ), array( 'menu_icon' => 'dashicons-universal-access', 'supports' => array( 'title', 'thumbnail', 'excerpt' ), 'exclude_from_search' => true, 'publicly_queryable' => false ) );

STM_PostType::registerPostType( 'testimonial', __( 'Testimonial', STM_DOMAIN ), array( 'menu_icon' => 'dashicons-testimonial', 'supports' => array( 'title', 'thumbnail', 'excerpt' ), 'exclude_from_search' => true, 'publicly_queryable' => false ) );

STM_PostType::registerPostType( 'gallery', __( 'Gallery Image', STM_DOMAIN ), array( 'menu_icon' => 'dashicons-format-gallery', 'supports' => array( 'title', 'thumbnail' ), 'exclude_from_search' => true, 'publicly_queryable' => false ) );

STM_PostType::registerPostType( 'donor', __( 'Donor', STM_DOMAIN ), array( 'supports' => array( 'title' ), 'exclude_from_search' => true, 'publicly_queryable' => false, 'show_in_menu' => 'edit.php?post_type=donation' ) );

STM_PostType::addMetaBox( 'page_options', __( 'Page Options', STM_DOMAIN ), array( 'page', 'post', 'event', 'donation' ), '', '', '', array(
	'fields' => array(
		'separator_page_background' => array(
			'label'   => __( 'Page Background', STM_DOMAIN ),
			'type'    => 'separator'
		),
		'page_bg_image' => array(
			'label' => __( 'Background Image', STM_DOMAIN ),
			'type'  => 'image'
		),
		'page_bg_position' => array(
			'label'   => __( 'Background Position', STM_DOMAIN ),
			'type'    => 'text'
		),
		'page_bg_repeat' => array(
			'label'   => __( 'Background Repeat', STM_DOMAIN ),
			'type'    => 'select',
			'options' => array(
				'repeat' => __( 'Repeat', STM_DOMAIN ),
				'no-repeat' => __( 'No Repeat', STM_DOMAIN ),
				'repeat-x' => __( 'Repeat-X', STM_DOMAIN ),
				'repeat-y' => __( 'Repeat-Y', STM_DOMAIN )
			)
		),
		'separator_title_box' => array(
			'label'   => __( 'Title Box', STM_DOMAIN ),
			'type'    => 'separator'
		),
		'title' => array(
			'label'   => __( 'Title', STM_DOMAIN ),
			'type'    => 'select',
			'options' => array(
				'show' => __( 'Show', STM_DOMAIN ),
				'hide' => __( 'Hide', STM_DOMAIN )
			)
		),
		'title_box_bg_color' => array(
			'label' => __( 'Background Color', STM_DOMAIN ),
			'type'  => 'color_picker'
		),
        'title_box_font_color' => array(
            'label' => __( 'Font Color', STM_DOMAIN ),
            'type'  => 'color_picker'
        ),
		'title_box_bg_image' => array(
			'label'   => __( 'Background Image', STM_DOMAIN ),
			'type'    => 'select',
			'options' => array(
                'none' => __('None', STM_DOMAIN),
                'default_1' => __('Default 1', STM_DOMAIN),
                'default_2' => __('Default 2', STM_DOMAIN),
                'default_3' => __('Default 3', STM_DOMAIN),
                'default_4' => __('Default 4', STM_DOMAIN),
                'default_5' => __('Default 5', STM_DOMAIN),
                'default_6' => __('Default 6', STM_DOMAIN),
                'default_7' => __('Default 7', STM_DOMAIN)
			)
		),
		'title_box_custom_bg_image' => array(
			'label' => __( 'Custom Background Image', STM_DOMAIN ),
			'type'  => 'image'
		),
		'title_box_bg_position' => array(
			'label'   => __( 'Background Position', STM_DOMAIN ),
			'type'    => 'text'
		),
		'title_box_bg_repeat' => array(
			'label'   => __( 'Background Repeat', STM_DOMAIN ),
			'type'    => 'select',
			'options' => array(
				'repeat' => __( 'Repeat', STM_DOMAIN ),
				'no-repeat' => __( 'No Repeat', STM_DOMAIN ),
				'repeat-x' => __( 'Repeat-X', STM_DOMAIN ),
				'repeat-y' => __( 'Repeat-Y', STM_DOMAIN )
			)
		),
	)
) );

STM_PostType::addMetaBox( 'donation_information', __( 'Donation Information', STM_DOMAIN ), array( 'donation' ), '', '', '', array(
	'fields' => array(
		'donation_target'   => array(
			'label' => __( 'Target Amount', STM_DOMAIN ),
			'type'  => 'text'
		),
		'donation_raised'   => array(
			'label' => __( 'Raised Amount', STM_DOMAIN ),
			'type'  => 'text'
		),
		'donation_currency' => array(
			'label' => __( 'Currency', STM_DOMAIN ),
			'type'  => 'text'
		),
		'donation_donors'   => array(
			'label' => __( 'Donors Count', STM_DOMAIN ),
			'type'  => 'text'
		)
	)
) );

STM_PostType::addMetaBox( 'sidebar_options', __( 'Sidebar Options', STM_DOMAIN ), array( 'page', 'post' ), '', '', '', array(
	'fields' => array(
		'sidebar_position' => array(
			'label'   => __( 'Sidebar Position', STM_DOMAIN ),
			'type'    => 'select',
			'options' => array(
				'right' => __( 'Right', STM_DOMAIN ),
				'left'  => __( 'Left', STM_DOMAIN ),
				'none'  => __( 'None', STM_DOMAIN )
			)
		)
	)
) );

STM_PostType::addMetaBox( 'volunteer_info', __( 'Volunteer Info', STM_DOMAIN ), array( 'volunteer' ), '', '', '', array(
	'fields' => array(
		'volunteer_email'   => array(
			'label' => __( 'Email', STM_DOMAIN ),
			'type'  => 'text'
		),
		'volunteer_age'   => array(
			'label' => __( 'Age', STM_DOMAIN ),
			'type'  => 'text'
		),
		'volunteer_city'   => array(
			'label' => __( 'City', STM_DOMAIN ),
			'type'  => 'text'
		),
		'volunteer_phone'   => array(
			'label' => __( 'Phone', STM_DOMAIN ),
			'type'  => 'text'
		),
		'volunteer_major'   => array(
			'label' => __( 'Major', STM_DOMAIN ),
			'type'  => 'text'
		),
		'volunteer_zip'   => array(
			'label' => __( 'ZIP code', STM_DOMAIN ),
			'type'  => 'text'
		),
		'volunteer_facebook'   => array(
			'label' => __( 'Facebook', STM_DOMAIN ),
			'type'  => 'text'
		),
		'volunteer_twitter'   => array(
			'label' => __( 'Twitter', STM_DOMAIN ),
			'type'  => 'text'
		)
	)
) );

STM_PostType::addMetaBox( 'testimonial_info', __( 'Testimonial Info', STM_DOMAIN ), array( 'testimonial' ), '', '', '', array(
    'fields' => array(
        'testimonial_city'   => array(
            'label' => __( 'City', STM_DOMAIN ),
            'type'  => 'text'
        )
    )
) );

STM_PostType::addMetaBox( 'donor_info', __( 'Donor Info', STM_DOMAIN ), array( 'donor' ), '', '', '', array(
	'fields' => array(
		'donor_email'   => array(
			'label' => __( 'Email', STM_DOMAIN ),
			'type'  => 'text'
		),
		'donor_phone'   => array(
			'label' => __( 'Phone', STM_DOMAIN ),
			'type'  => 'text'
		),
		'donor_address'   => array(
			'label' => __( 'Address', STM_DOMAIN ),
			'type'  => 'text'
		),
		'donor_note'   => array(
			'label' => __( 'Additional Note', STM_DOMAIN ),
			'type'  => 'text'
		),
		'donor_amount'   => array(
			'label' => __( 'Amount', STM_DOMAIN ),
			'type'  => 'text'
		),
		'donor_donation'   => array(
			'label' => __( 'Donation', STM_DOMAIN ),
			'type'  => 'text'
		)
	)
) );

add_action( 'admin_menu', 'stm_register_donation_options_menu' );

if( ! function_exists( 'stm_register_donation_options_menu' ) ){
	function stm_register_donation_options_menu(){
		add_submenu_page( 'edit.php?post_type=donation', __('Donation options', STM_DOMAIN), __('Donation options', STM_DOMAIN), 'manage_options', 'donation', 'stm_donation_options' );
	}
}

if( ! function_exists( 'donation_options' ) ){
	function stm_donation_options(){

		if ( ! empty( $_POST['donation_options'] ) ) {
			set_theme_mod( 'donation_options', $_POST['donation_options'] );
		}

		$options = get_theme_mod( 'donation_options' );

		$defaultDonationOptions = array(
			'email'               => 'paypalemail@gmail.com',
			'currency'            => 'USD',
			'admin_email_subject' => 'Put email subject Here',
			'admin_email_message' => 'Put email content Here',
			'donor_email_subject' => 'Put email subject Here',
			'donor_email_message' => 'Put email content Here',
			'mode'                => 'sandbox'
		);

		$options = wp_parse_args( $options, $defaultDonationOptions );

		echo '
			<div class="wrap">
		        <h2>Donation options</h2>

		        <form method="POST" action="">
		            <table class="form-table">
		                <tr valign="top">
		                    <th scope="row">
		                        <label for="email">' . __( 'Paypal email:', STM_DOMAIN ) . '</label>
		                    </th>
		                    <td>
		                        <input type="text" id="email" name="donation_options[email]" value="' . $options['email'] . '"  size="25" />
		                    </td>
		                </tr>
		                <tr valign="top">
		                    <th scope="row">
		                        <label for="currency">' . __( 'Currency code:', STM_DOMAIN ) . '</label>
		                    </th>
		                    <td>
		                        <input type="text" id="currency" name="donation_options[currency]" value="' . $options['currency'] . '" size="25" /> ex. USD
		                    </td>
		                </tr>
		                 <tr valign="top">
		                    <th scope="row">
		                        <label for="currencyCode">' . __( 'Mode:', STM_DOMAIN ) . '</label>
		                    </th>
		                    <td>
		                        <select name="donation_options[mode]">
		                            <option value="live" ' . ( ( $options['mode'] == 'live' ) ? 'selected="true"' : '' ) . '>' . __( 'Live', STM_DOMAIN ) . '</option>
		                            <option value="sandbox" ' . ( ( $options['mode'] == 'sandbox' ) ? 'selected="true"' : '' ) . '>' . __( 'Sandbox', STM_DOMAIN ) . '</option>
		                        </select>
		                    </td>
		                </tr>
		                <tr valign="top">
		                    <th scope="row">
		                        <label for="adminEmailSubject">' . __( 'Admin email subject:', STM_DOMAIN ) . '</label>
		                    </th>
		                    <td>
		                        <input type="text" size="45" id="adminEmailSubject" name="donation_options[admin_email_subject]"  value="' . $options['admin_email_subject'] . '" />
		                    </td>
		                </tr>
		                <tr valign="top">
		                    <th scope="row">
		                        <label for="adminEmailBody">' . __( 'Admin email body:', STM_DOMAIN ) . '</label>
		                    </th>
		                    <td>
		                        <textarea  cols="70" rows="10" id="adminEmailBody" name="donation_options[admin_email_message]"  >' . $options['admin_email_message'] . '</textarea>
		                        <p><b>' . __( 'Shortcodes:', STM_DOMAIN ) . '</b> <br />
		                            [name] -  ' . __( 'Donor name', STM_DOMAIN ) . ',
		                            [amount] - ' . __( 'Donate amount', STM_DOMAIN ) . ',
		                            [cause] - ' . __( 'Cause name', STM_DOMAIN ) . '
		                        </p>
		                    </td>
		                </tr>
		                <tr valign="top">
		                    <th scope="row">
		                        <label for="donorEmailContent">' . __( 'Donor email subject:', STM_DOMAIN ) . '</label>
		                    </th>
		                    <td>
		                        <input type="text" size="45" id="donorEmailSubject" name="donation_options[donor_email_subject]"  value="' . $options['donor_email_subject'] . '" />
		                    </td>
		                </tr>
		                <tr valign="top">
		                    <th scope="row">
		                        <label for="donorEmailBody">' . __( 'Donor email body:', STM_DOMAIN ) . '</label>
		                    </th>
		                    <td>
		                        <textarea  cols="70" rows="10" id="donorEmailBody" name="donation_options[donor_email_message]"  >' . $options['donor_email_message'] . '</textarea>
		                        <p><b>' . __( 'Shortcodes:', STM_DOMAIN ) . '</b> <br />
		                            [name] -  ' . __( 'Donor name', STM_DOMAIN ) . ',
		                            [amount] - ' . __( 'Donate amount', STM_DOMAIN ) . ',
		                            [cause] - ' . __( 'Cause name', STM_DOMAIN ) . '
		                        </p>
		                    </td>
		                </tr>
		            </table>
		            <p>
						<input type="submit" value="' . __( 'Save settings', STM_DOMAIN ) . '" class="button-primary"/>
					</p>
		        </form>
		    </div>
		';
	}
}

Gracias, un saludo! :encouragement:
 
Hola.

Dentro de la funcion register_post_type es posible cambiar esa parte ---> https://codex.wordpress.org/Function_Reference/register_post_type

Con la opcion de rewrite:
Insertar CODE, HTML o PHP:
'rewrite' => array( "slug" => "eventos" )


Intenta con: (codigo no probado)

Insertar CODE, HTML o PHP:
STM_PostType::registerPostType( 'event', __( 'Event', STM_DOMAIN ), 
	array( 'menu_icon' => 'dashicons-calendar', 
		   'supports' => array( 'title', 'editor', 'thumbnail', 'comments' ), 
		   'taxonomies' => array( 'post_tag' ),
		   'rewrite' => array( "slug" => "eventos" )
		   ) 
	);

Recuerda volver a generar los permalinks para que no te de 404.

Espero esto te ayude. Saludos.
 
Última edición:
Efectivamente, funciono perfectamente, eres un genio. 🙂

Muchas gracias Sergio, saludos! :encouragement:
 
Atrás
Arriba