尝试以下操作:(在functions.php中复制并粘贴下面的代码)
// Get page url >> webcheatsheet.com/php/get_current_page_url.php
function itp_current_page_url() {
$page_url = \'http\';
if( isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on" ) { $page_url .= "s" ;}
$page_url .= "://";
if( $_SERVER["SERVER_PORT"] != "80" ) {
$page_url .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$page_url .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $page_url;
} // end itp_current_page_url
// Jetpack subscription form shortcode by http://www.itechplus.org
function itp_jetpack_subscription_form_shortcode( $atts, $content = \'\', $code = \'\' ) {
extract( shortcode_atts( array(
\'title\' => \'Email Subscription\',
\'desc\' => \'Enter your email address to subscribe to this website and receive notifications of new articles by email.\',
\'button\' => \'Subscribe\',
\'placeholder\' => \'Email Address\',
), $atts ) );
global $post;
// Build current page url
if( is_home() || is_front_page() ) {
$url = home_url(\'/\');
} elseif( is_singular() ) {
$url = get_permalink($post->ID);
} else {
$url = itp_current_page_url();
}
$jetpack_subscribe = \'\';
// Build jetpack subscription form
if( $title != \'\' ) {
$jetpack_subscribe .= \'<h3 class="widget-title">
<label for="subscribe-field">\' . $title . \'</label>
</h3>\';
}
$jetpack_subscribe .= \'<form id="subscribe-blog-blog_subscription-\' . time() . \'" accept-charset="\' . get_bloginfo( \'charset\' ) . \'" method="post" action="">\';
if( $desc != \'\' ) {
$jetpack_subscribe .= \'<p>\' . $desc . \'</p>\';
}
$jetpack_subscribe .= \'<p>
<input id="subscribe-field" class="input email" type="email" placeholder="\'. $placeholder .\'" onblur="if( this.value == \\\'\\\' ) { this.value = \\\'\' . $placeholder . \'\\\'; }" onclick="if ( this.value == \\\'\' . $placeholder . \'\\\' ) { this.value = \\\'\\\'; }" value="\' . $placeholder . \'" style="width: 95%; padding: 1px 2px" name="email" />
</p>
<p>
<input type="hidden" value="subscribe" name="action" />
<input type="hidden" value="\' . $url . \'" name="source" />
<input type="hidden" value="widget" name="sub-type">
<input type="hidden" value="blog_subscription-\' . time() . \'" name="redirect_fragment" />
<input type="submit" class="input subbmit" name="jetpack_subscriptions_widget" value="\' . $button . \'" />
</p>
</form>\';
return $jetpack_subscribe;
}
add_shortcode( \'itp_email_subscription\', \'itp_jetpack_subscription_form_shortcode\' );
安装并激活Jetpack后,在任何页面或任何文本小部件上应用快捷码,从而:
[itp_email_subscription title="Some Title" desc="Some description here" placeholder="Placeholder" button="Button"]
完成!但未经测试。如果有任何bug,请告诉我。快乐编码:-)