How can I place a default text (hashtag) in the Custom Message?
The textarea is (located in line 643) under jetpack/modules/publicize/ui.php
I tried to put the text in front of $title in various ways, like:
<?php echo "#myhashtag $title"; ?>
or
<?php echo '#myhashtag '.$title; ?>
but it just echoes the text, not the $title.
Any ideas will be greatly appreciated.
You can use the approach of this Wordpress plugin i made (Publicize With Hashtags), which does exactly that. It basically use and action trigger bound to the 'save_post' native event.
If you want to develop your own one you can have a look at my Source Code on the project's GitHub page or in this installation & usage guide I wrote about it.
You can add a filter, like so, to your theme's functions.php or a site-specific plugin:
add_filter( 'wpas_default_prefix', 'add_default_publicize_hashtag_prefix', 10, 4 );
function add_default_publicize_hashtag_prefix() {
$default_tags = '#yourhastaghere ';
return $default_tags;
}
This will add your default hashtag before your title without you needing to hack the WordPress core.
jetpack/modules/publicize/ui.php itself states in its comments:
/**
* Only user facing pieces of Publicize are found here.
*/
You added your hashtag in the textarea which allows admins to enter a custom message (click edit and it will slide down with your hashtag).
As #Yazmin mentioned, the best way to permanently edit the message is using a filter. The filters available are wpas_default_prefix, wpas_default_message, and wpas_default_suffix.
Personally, I had no success using these filters and I'm interested in a working solution to this issue myself.
Related
I need to write pure PHP codes in WP posts - not using a plugin or snippets etc.
I know this Q has been asked before, but all were answered by using plugins etc.
There were some plugins like PHP-Exec that could do the job, but due to latest WP/PHP updates they no longer work.
Is there any way to write some functions in FUNCTIONS.PHP to allow this?
So a code like this can work as a WP post?
<p>
My text paragraph.
</p>
<?php
// Custom PHP codes - vary in wp posts
echo "Anything ... ";
?>
<p>
My second text paragraphs.
</p>
Thanks a lot guys!
Best approach would be to wrap your PHP code in a shortcode inside functions.php and then call it out of your page.
function anything_function() {
// your actual functionality.
$message = "Anything ... ";
return $message;
}
// register shortcode
add_shortcode('anything', 'anything_function');
And then you can use the [anything] shortcode inside your templates.
Please refer to Shortcode API for more information.
After digging internet for an answer I cannot find any idea about how to deal with my issue. I think the problem is common for someone who knows PHP a little bit.
To describe the situation. For some custom WordPress plugin I've got two PHP files: ff_config.php and loantest_form.php. First file contains some configurations of plugin plus following lines:
/**--------------------------TABLE SHORTCODES-----------------------*/
function render_loantest_form() {
include(plugin_dir_path(__FILE__) . 'front/loantest_form.php');
}
add_shortcode( 'render_loantest_form' , render_loantest_form );
/**--------------------------DISPLAY PLUGIN IN FOOTER-----------------------*/
add_action('wp_footer', 'display_loantest');
function display_loantest() {
echo render_loantest_form();
}
Which I suppose rendering second file containing enqueue scripts (js/css) and whole HTML output and placing in wp_footer where it exactly is on my page.
The question is: how to change mentioned lines to allow me to place render result (loantest_form.php) in specific div / id on page (for example #sidebar-slider)?
If you want to display your shortcode in a template file,
echo do_shortcode('[render_loantest_form]');
Enable the use of shortcodes in text widgets.
add_filter( 'widget_text', 'do_shortcode' );
And inside the text editor
[render_loantest_form]
You can read more about do_shortcode()
Note that you need to be sure that the file load in the render function is good and that it returns the expect content.
I am trying to write a plugin for wordpress. I have a problem i can't solve.
Inside plugin i habe added a shortcode that show a form.
function showForm() {
echo '<form method="post" action="www.example.com/myDestinationPage">';
[...]
}
add_shortcode( 'ShowFormSC' , 'showForm' );
After that, in a page, i added the shortcode and it works perfectly. ;-)
Now the problem: how can i read POST data in myDestinationPage (another wordpress page)?
In Php would be very simple ... but in wordpress I do not know how to do.
Second problem: myDestinationPage must be a real wordpress page with another shortcode inside, or can be defined as a "virtual" page inside my plugin?
Thank you for your help!
Best Regards,
Simone
www.example.com/myDestinationPage needs to be edited to recieve the post data, just as in any other php script, wordpress or not. If 'myDestinationPage' resolves to dynamic wordpress content, then you are in muddy waters.
Let's say, myDestinationPage is a wordpress Post. That "page" doesn't exist as a file, it comes directly from the database.
You could write a shortcode which handles this though:
add_shortcode('post_parser', 'postParser');
. . .
function postParser() {
filter_input(INPUT_POST, 'my_post_value');
//do something
}
Then, you just add the '[post_parser]' shortcode to the myDestinatioPage Post. (You mentioned it's a wordpress page, but page & post are both WP_Post objects.)
Another option is to put your post processing code in the post.php (or whichever template myDestinationPage is).
1st answer: you can directly use $_POST in wordpress like in php.
2nd answer: Yes you can. If you want to use pages in your plugin, use plugins_url() to generate the path for form action.
https://codex.wordpress.org/Function_Reference/plugins_url
so we are making a wordpress site that automatically adds a link to a comment every time a comment is created. The theme we are using is html5 blank. I have written several lines of code into its function.php. however it is not working right now, here is what i wrote:
function bo_wrap_comment_text($content) {
$content = get_comment_text();
$texta = urlencode(get_comment_text());
$textb = "http://www.google.com/search?btnI&q=" + $texta;
return ''.$content.'';
}
add_filter('wp_insert_comment','bo_wrap_comment_text',1000);
a separate code(this one works) is tested here: http://phpfiddle.org and the code is:
<?php
$texta='i hate apple';
$textb=urlencode($texta);
$textc= "http://www.google.com/search?btnI&q=".$textb;
echo ''.$texta.'';
?>
the wordpress site is here. It is simply a static front page. the title you see there is the title of comment area. everything related with blog posts has been hidden using css. we have manually added links to several comments as prototyping. what we want is replace manual work with wordpress functions. I would really appreciate any help.
You need this hook instead to edit comment data:
http://codex.wordpress.org/Plugin_API/Filter_Reference/preprocess_comment
My question: Is there any way of showing the visitor's IP address in the title of a page on Wordpress? What I've done so far is this: My IP Lookup.
Is there any plugin or a tweak that I can do to?
Here's the file: Header.php
Please help!!
I'm the author of the theme and its framework. I'm just going to modify the code that Matthew gave you a bit. For future updates to the theme and framework, it's better if you can avoid actually editing header.php in your Child theme, but instead utilize the framework's hook system:
http://www.wpjumpstart.com/tutorial/primary-framework-action-hooks/
themeblvd_title is one of the framework's actions. It has a default function already hooked onto it that displays the title the way you see it now. What you want to do is fairly easy because you're not actually modifying that default function, but instead just adding onto the action.
If the concept of action hooks in general is completely foreign to you, definitely check out this article -- www.wpjumpstart.com/tutorial/actions/ -- Understanding these basic WordPress development concepts is really going to expand what you're going to be able to do moving forward with your customizations.
So to accomplish what Mathew said, you'd do the following from the functions.php of your Child theme:
function my_title_addon() {
if (is_page(10)) { //Check if we are on the correct page
echo '|'; //Just a spacer between the default title and your addition
do_shortcode('[shortcode]');
}
}
add_action( 'themeblvd_title', 'my_title_addon' );
There's also one big thing to note here, as well. I noticed on your site, you're using Alyeska 2.0. You should update to the latest version Alyeska 2.1 posted last week on ThemeForest, which incorporates v2.1 of the framework. Inside is a new sample child theme that incorporates a slightly modified structure, as outlined in this video -- vimeo.com/41331677
If you do not use this new child theme structure, the above code I posted will add your IP shortcode to the start of themeblvd_title, which isn't what you want. If you elect to keep your current theme version and Child theme structure, the above add_action needs to have a priority higher than the default 10 like this:
function my_title_addon() {
if (is_page(10)) { //Check if we are on the correct page
echo '|'; //Just a spacer between the default title and your addition
do_shortcode('[shortcode]');
}
}
add_action( 'themeblvd_title', 'my_title_addon', 11 ); // Higher priority so it comes after default title function
Here is how you can use a filter hook to modify the title.
Add this in a theme functions.php file or one of your own plugins:
add_filter( 'wp_title', 'add_ip_to_title', 10, 3 );
function add_ip_to_title($title, $sep = '', $location = '') {
return $title . $sep . "visitor IP info here";
}
https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_title
Edit your header.php file in your theme. That is where the tag is generated. It should be wp-content/themes/alyeska-child/header.php or if it isn't there wp-content/themes/alyeska/header.php.
If you post the code that is generating your title (or your header.php file if you can't tell), we can tell you where to add it specifically.
If the IP info is generated via a shortcode, you can use do_shortcode('[shortcode]) in your PHP to run the shortcode directly with PHP.
If you wanted to do this on just one page, you would have to detect the correct page and conditionalize the change to the title. You need to know a page identifyer for the page you want, but you would use something like:
<title>
<?php
themeblvd_title();
if (is_page(10)) { //Check if we are on the correct page
echo '|'; //Just a spacer between the default title and your addtion
do_shortcode('[shortcode]');
}
?>
</title>
More information on is_page: http://codex.wordpress.org/Function_Reference/is_page
To add to some of the other answers, to get their IP address, it could vary a little bit depending upon your server environment. Just make a file called test.php and put it in a web accessible place:
<?php
echo phpinfo();
?>
Then, look for a place where you can retrieve the user's IP address. If your PHP is running in a reverse proxy, unfortunately, the normal place will just have localhost's IP. But there are a lot of other environmental variables you can grab the IP from. Here are the places to check:
"Apache Environment" or "HTTP Headers Information" or under the "PHP Variables" section.
Then, if you see the real IP address (compare the address shown on the info page with what you might get from whatismyip.com) then you can access that value in the function described above by drew010 using one of PHP's predefined variables.