Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何制作WordPress';s<;?php_title_属性()&燃气轮机;为空格渲染%20?_Php_Wordpress_Html_Standards - Fatal编程技术网

如何制作WordPress';s<;?php_title_属性()&燃气轮机;为空格渲染%20?

如何制作WordPress';s<;?php_title_属性()&燃气轮机;为空格渲染%20?,php,wordpress,html,standards,Php,Wordpress,Html,Standards,我正在尝试呈现一个100%兼容HTML5的WordPress主题,并且已经设法克服了除了一个障碍之外的所有障碍 在某些帖子的末尾,我显示了一个“Tweet”链接,该链接在主题模板中使用了以下源代码: <a href="http://twitter.com/share?text=<?php the_title_attribute(); ?>&amp;via=ianhines&amp;url=<?php echo simple_url_shortener(''

我正在尝试呈现一个100%兼容HTML5的WordPress主题,并且已经设法克服了除了一个障碍之外的所有障碍

在某些帖子的末尾,我显示了一个“Tweet”链接,该链接在主题模板中使用了以下源代码:

<a href="http://twitter.com/share?text=<?php the_title_attribute(); ?>&amp;via=ianhines&amp;url=<?php echo simple_url_shortener('','service=bit.ly+key&apikey=R_a6dc414291bb882024ddd99690f5eb61&login=ianhines&cache=no'); ?>" title="Share This Article on Twitter">Tweet</a>

有没有办法强制WordPress将此URL字符串中的空格呈现为%20,从而使我的网站完全符合HTML5的要求?

好的,只需将
标题属性()包装为:


编辑


我添加了
echo=0
以返回文本,而不是显示文本,请参见。

我的建议是使用
the_title\u attribute()
的echo参数和
urlencode()
空格:

<a href="http://twitter.com/share?text=<?php echo urlencode(the_title_attribute('', '', 0)); ?>&amp;via=ianhines&amp;url=<?php echo simple_url_shortener('','service=bit.ly+key&apikey=R_a6dc414291bb882024ddd99690f5eb61&login=ianhines&cache=no'); ?>" title="Share This Article on Twitter">Tweet</a>

将值0传递给
属性()
使其返回而不是回显其结果

<?php 
  $urltitle= str_replace(' ','%20',the_title_attribute('echo=0')); //value of 0 to return rather than echo result  
?> 

<a href="http://twitter.com/share?text=<?php echo $urltitle; ?>&amp;via=ianhines&amp;url=<?php echo simple_url_shortener('','service=bit.ly+key&apikey=R_a6dc414291bb882024ddd99690f5eb61&login=ianhines&cache=no'); ?>" title="Share This Article on Twitter">Tweet</a>

title\u属性()
实际上
echo
会删除文本,因此这不起作用。
<?php
ob_start();
the_title_attribute();
$title = ob_get_clean();
?>
/share?text=<?php echo urlencode($title); ?>&amp;via=
/share?text=<?php echo urlencode(the_title_attribute('echo=0')); ?>&amp;via=
<?php
    $spaceurl=the_title_attribute('echo=0');
    $nonspaceurl=preg_replace('\s','%20',spaceurl);
?>

<a href="<?php echo $nonspaceurl; ?>">
    my link text
</a>
<a href="http://twitter.com/share?text=<?php echo urlencode(the_title_attribute('', '', 0)); ?>&amp;via=ianhines&amp;url=<?php echo simple_url_shortener('','service=bit.ly+key&apikey=R_a6dc414291bb882024ddd99690f5eb61&login=ianhines&cache=no'); ?>" title="Share This Article on Twitter">Tweet</a>
<?php 
  $urltitle= str_replace(' ','%20',the_title_attribute('echo=0')); //value of 0 to return rather than echo result  
?> 

<a href="http://twitter.com/share?text=<?php echo $urltitle; ?>&amp;via=ianhines&amp;url=<?php echo simple_url_shortener('','service=bit.ly+key&apikey=R_a6dc414291bb882024ddd99690f5eb61&login=ianhines&cache=no'); ?>" title="Share This Article on Twitter">Tweet</a>