¿Estás buscando una forma de mostrar mensajes aleatorios de aliento cuando se crea una publicación? Este fragmento te permitirá mostrar mensajes de aliento a un autor cuando crea una nueva publicación. Los mensajes se muestran en el campo del título y en el campo del contenido de las nuevas publicaciones.
Instrucciones:
Todo lo que tienes que hacer es agregar este código al archivo functions.php de tu tema o a un plugin específico para tu sitio. Puedes editar los arrays de mensajes para adaptarlos a tus necesidades.
add_filter( 'default_content', 'writingEncouragement' );
function writingEncouragement( $content ) {
global $post_type;
if($post_type == "post"){
$encArray = array( "Welcome! Please write a nice and informative page or post!",
"Now I know this will be some great piece you're going to write!",
"<h1>Don't procrastinate!</h1>",
"Finally started, huh? Okay then!",
"Blah blah blah. Why don't you write something good this time?",
"You were just SO GOOD last time, I hope you measure up now too",
"Error 404.... Just kidding",
"If you have an SEO plugin, don't forget to add the meta title and meta description information",
"You are now participating on what is called \"on-site SEO \" where you create useful content, put keywords into the URL and optimize your meta information",
"This little piece of code can be used to create a wordpress signature or to automatically populate advertisement code"
);
$content = $encArray[array_rand($encArray)];
return $content;
}
}
function title_text_input( $title ){
$title = array( "Enter a GOOD, CREATIVE Title!",
"404 Post Not Found, I guess you can just rewrite it",
"Title rich in KEYWORDS goes here",
"Enter Title",
"Enter Writing Mode",
"How To: Write a GOOD post",
"Top 10 whatever"
);
$title = $title[array_rand($title)];
return $title;
}
add_filter( 'enter_title_here', 'title_text_input' );
Nota: Si es la primera vez que agregas fragmentos de código en WordPress, consulta nuestra guía sobre cómo copiar y pegar fragmentos de código correctamente en WordPress, para no dañar accidentalmente tu sitio.
Si te gustó este fragmento de código, considera echar un vistazo a nuestros otros artículos en el sitio como: 30 formas de ganar dinero en línea blogueando (a tiempo parcial) y más de 100 estadísticas y datos interesantes de WordPress.
[…] truco (encontrado en wpsnipp) funciona llenando la Caja de Título y/o la Caja del Editor con texto predefinido. Y así cuando un […]