How can I add my site URL (e.g.: test.com) on every beginning of my WordPress content, so it becomes like this:
test.com - Lorem ipsum dollor bla bla bla Lorem ipsum dollor bla bla bla Lorem ipsum dollor bla bla bla
I hope someone can help.
This will give the result you want
<?php
var $content_fetch = explode('://',home_url());
echo $content_fetch[1];
?>
you can echo like this
<?php echo $content_fetch[1];?> - Lorem ipsum dollor bla bla bla
You could do something like this
//The filter for changing content without saving it in DB
add_filter( 'the_content', 'stender_filter_the_content');
function stender_filter_the_content( $content ) {
// Check if we're inside the main loop in a single post page.
if ( is_single() && in_the_loop() && is_main_query() ) {
return "test.com -> ".$content;
}
return $content;
}
This should add your text, on single posts, without changing it on the archives.
/EDIT/
Since you need it to be the first word, you might be able to do something like this instead.
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'stender_filter_the_content', 30 );
function stender_filter_the_content( $content ) {
// Check if we're inside the main loop in a single post page.
if ( is_single() && in_the_loop() && is_main_query() ) {
return "test.com -> ".$content;
}
return $content;
}
add_filter( 'the_content', 'wpautop' , 99 );
This is just an idea though - Haven't tested it.
I assumed you want to have this text on top of the large text probably. In that case you should use the the_content
filter of Wordpress. You can define your own filter in a plugin or your theme's functions.php. For example:
add_filter('the_content', 'addUrlToContent', 10, 1);
As soon as the_content()
is called somewhere in your theme this will execute the corersponding filter. So it generates the content, then sends the content to your filter function (in this case addUrlToContent()
) which can do whatever it wants with the content before it is being returned to the theme. The last two arguments are the priority (you may have multiple filters on the same 'the_content' hook and want to execute them in a certain order) and the number of arguments you expect in the function. In this case just 1 ($content).
Your addUrlToContent()
function should look like this:
function addUrlToContent($content) {
$content = "test.com: " . $content;
return $content;
}
That's it!